Python/C3/Sets/English-timed

From Script | Spoken-Tutorial
Revision as of 15:40, 28 March 2013 by Sneha (Talk | contribs)

Jump to: navigation, search
Timing Narration
0:00 Hello friends and welcome to the tutorial on 'Sets'.
0:05 At the end of this tutorial, you will be able to,
  1. Create sets from lists.
  2. Perform union, intersection and symmetric difference operations.
  3. Check if a set is a subset of other.
  4. Understand various similarities with lists like length and containership.
0:25 Before beginning this tutorial,we would suggest you to complete the tutorial on "Getting started with List"
0:35 Now, type ipython in the command.
0:43 So, What are sets?
0:46 Sets are data structures which contain unique elements.
0:49 In other words, duplicates are not allowed in sets.
0:54 Lets look at how to input sets.
0:59 So type a underscore list is equal to within brackets 1,2,1,4,5,6,2.
1:15 Then a is equal to set in brackets 'a' underscore list.
1:25 Then type 'a'.
1:28 We can see that duplicates are removed and the set contains only unique elements.
1:31 Now let us perform some operations on sets.
1:35 For this, we shall first create a pair of sets
1:40 f10 is equal to set in brackets and square brackets 1,2,3,5,8
1:54 p10 is equal to set of within brackets and square brackets 2,3,5,7.
2:07 f10 is the set of fibonacci series numbers from 1 to 10.
2:19 p10 is the set of prime numbers from 1 to 10.
2:22 Various operations can be performed on sets.
2:25 For example, The vertical bar and in bracket pipe character stands for union.
2:37 So type f10 then a vertical bar then p10 and hit Enter.
2:46 It gave the union of f10 and p10.
2:50 The ampersand character stands for intersection.
2:53 So type f10 ampersand p10.
3:00 It gave the intersection of f10 and p10 similarly.
3:05 f10 - p10 gives all the elements that are in f10 but not in p10 .
3:13 So type f10 hyphen p10
3:22 and f10 charat p10 gives all the elements in f10 union p10 but not in f10 intersection p10. So type f10 charat p10.
3:40 In mathematical terms, it gives the symmetric difference.
3:46 Sets also support checking of subsets.
3:50 So lets type b is equal to in brackets and square brackets 1,2.
4:00 Then b is less than f10.
4:05 It gives a True since b is a proper subset of f10.
4:09 Similarly, type f10 less than f10.
4:15 It gives a False since f10 is not a proper subset.
4:19 Hence the right way to do would be f10 less than or equal to f10.
4:31 we get a True since every set is a subset of itself.
4:37 Sets can be iterated upon just like lists and tuples.
4:42 for i in f10 colon in the command and then type print i comma
5:01 It prints the elements of f10.
5:03 The length and container ship check on sets is similar as in lists and tuples.
5:12 So type len within brackets f10 and hit Enter.
5:22 And It shows 5, type 1 in f10.
5:27 Then type 2 in f10.
5:33 And prints True and True respectively
5:45 Now, pause the video here, try out the following exercise and resume the video.
5:50 Given a list of marks, marks is equal to within square brackets 20, 23, 22, 23, 20, 21, 23
6:01 list all the duplicates
6:04 Duplicates marks are the marks left out when we remove each element of the list exactly one time.
6:13 So type marks is equal to in square brackets 20,23,22,23,20,21,23.
6:33 Then type marks underscore set is equal to set within bracket marks.
6:44 then for mark in marks underscore set colon, then marks dot remove within brackets mark.
7:05 We are now left with only duplicates in the list marks +
7:10 Hence Type duplicates is equal to set marks and hit enter.
7:24 Then type duplicate.
7:27 Hence, We obtained our required solution
7:30 This brings us to the end of the tutorial.
7:34 In this tutorial, we have learnt to,
7:36 Make sets from lists.
7;37 , & and ^ respectively.
7:49 Check if a set is a subset of other using the ' and ' = operators.
7:58 Then, Understand various similarities with lists like length and containership.
8:05 Here are some self assessment questions for you to solve
8:09 1. First one, If a is equal to within square brackets 1, 1, 2, 3, 3, 5, 5, 8
8:18 And What is set(a)
8:23 The options are
8:26 set within brackets and square brackets 1, 1, 2, 3, 3, 5, 5, 8
8:31 Second one set within brackets 1, 2, 3, 5, 8
8:36 Then the third option set([1, 2, 3, 3, 5, 5])
8:41 Then the last option is Error.
8:43 2. Second question, odd is equal to set within brackets 1, 3, 5, 7, 9 and squares is equal to set within brackets 1, 4, 9, 16
8:57 How do you find the symmetric difference of these two sets?
9:02 3. The third questions is, a is a set.
9:05 how do you check if a variable b exists in a ?
9:11 Now And the answers,
9:15 1. First answer is, set of a will have all the common elements in the list a , that is set within brackets 1, 2, 3, 5, 8
9:28 2. The Second answer is , To find the symmetric difference between two sets, we use the operator charat.
9:37 So type odd charat squares
9:42 3. Final answer is, To check the container ship, we say,
9:45 b in a
9:50 So Hope you have enjoyed this tutorial and found it useful.
9:53 Thank you!

Contributors and Content Editors

Gaurav, Minal, PoojaMoolya, Sneha