20 Checklist OK? : <put date stamp here, if OK> [2010-10-05] |
20 Checklist OK? : <put date stamp here, if OK> [2010-10-05] |
21 |
21 |
22 Script |
22 Script |
23 ------ |
23 ------ |
24 |
24 |
|
25 {{{ Show the slide containing title }}} |
|
26 |
25 Hello friends and welcome to the tutorial on Sets |
27 Hello friends and welcome to the tutorial on Sets |
26 |
|
27 {{{ Show the slide containing title }}} |
|
28 |
28 |
29 {{{ Show the slide containing the outline slide }}} |
29 {{{ Show the slide containing the outline slide }}} |
30 |
30 |
31 In this tutorial, we shall learn |
31 In this tutorial, we shall learn |
32 |
32 |
33 * sets |
33 * sets |
34 * operations on sets |
34 * operations on sets |
35 |
35 |
36 Sets are data structures which contain unique elements. In other words, |
36 Sets are data structures which contain unique elements. In other words, |
37 duplicates are not allowed in sets. |
37 duplicates are not allowed in sets. |
38 |
38 |
39 Lets look at how to input sets. |
39 Lets look at how to input sets. |
40 type |
40 type |
41 :: |
41 :: |
42 |
42 |
43 a_list = [1, 2, 1, 4, 5, 6, 7] |
43 a_list = [1, 2, 1, 4, 5, 6, 2] |
44 a = set(a_list) |
44 a = set(a_list) |
45 a |
45 a |
46 |
46 |
47 We can see that duplicates are removed and the set contains only unique |
47 We can see that duplicates are removed and the set contains only unique |
48 elements. |
48 elements. |
53 |
53 |
54 f10 is the set of fibonacci numbers from 1 to 10. |
54 f10 is the set of fibonacci numbers from 1 to 10. |
55 p10 is the set of prime numbers from 1 to 10. |
55 p10 is the set of prime numbers from 1 to 10. |
56 |
56 |
57 Various operations that we do on sets are possible here also. |
57 Various operations that we do on sets are possible here also. |
58 The | character stands for union |
58 The | (pipe) character stands for union |
59 :: |
59 :: |
60 |
60 |
61 f10 | p10 |
61 f10 | p10 |
62 |
62 |
63 gives us the union of f10 and p10 |
63 gives us the union of f10 and p10 |
87 :: |
87 :: |
88 |
88 |
89 b = set([1, 2]) |
89 b = set([1, 2]) |
90 b < f10 |
90 b < f10 |
91 |
91 |
92 gives a True since b is a proper subset of f10. |
92 gives a ``True`` since b is a proper subset of f10. |
93 Similarly, |
93 Similarly, |
94 :: |
94 :: |
95 |
95 |
96 f10 < f10 |
96 f10 < f10 |
97 |
97 |
98 gives a False since f10 is not a proper subset. |
98 gives a ``False`` since f10 is not a proper subset. |
99 hence the right way to do would be |
99 hence the right way to do would be |
100 :: |
100 :: |
101 |
101 |
102 f10 <= f10 |
102 f10 <= f10 |
103 |
103 |
104 and we get a True since every set is a subset of itself. |
104 and we get a ``True`` since every set is a subset of itself. |
105 |
105 |
106 Sets can be iterated upon just like lists and tuples. |
106 Sets can be iterated upon just like lists and tuples. |
107 :: |
107 :: |
108 |
108 |
109 for i in f10: |
109 for i in f10: |
159 * How to check if a set is a subset of other |
159 * How to check if a set is a subset of other |
160 * The various similarities with lists like length and containership |
160 * The various similarities with lists like length and containership |
161 |
161 |
162 {{{ Show the "sponsored by FOSSEE" slide }}} |
162 {{{ Show the "sponsored by FOSSEE" slide }}} |
163 |
163 |
164 #[Nishanth]: Will add this line after all of us fix on one. |
|
165 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India |
164 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India |
166 |
165 |
167 Hope you have enjoyed and found it useful. |
166 Hope you have enjoyed and found it useful. |
168 Thank you! |
167 Thank you! |
169 |
168 |