Difference between revisions of "Python/C3/Sets/English-timed"

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

Latest revision as of 12:42, 27 March 2017

Time Narration
00:00 Hello friends and welcome to the tutorial on 'Sets'.
00:05 At the end of this tutorial, you will be able to

Create sets from lists. Perform union, intersection and symmetric difference operations. Check if a set is a subset of other. Understand various similarities with lists like length and containership.

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

Contributors and Content Editors

Gaurav, Minal, PoojaMoolya, Sneha