File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Sets :- is a collection of items that are unordered(hence unindexed), unchangeable
2
+ # and do not contain duplicate values.
3
+
4
+ # A set is faster than list
5
+
6
+ utensils = {"fork" , "knife" , "spoon" } #Creation of sets
7
+ dishes = {"bowl" , "plate" , "cup" , "knife" }
8
+
9
+ print (dishes )
10
+ print (utensils ) #On running the program multiple times it gives out different
11
+ #output each single time i.e the order in which elements are
12
+ #displayed is different each single time
13
+ # To add argument to the given set
14
+ # utensils.add("spatula")
15
+ # print(utensils)
16
+
17
+ # To remove element from the given set
18
+ # utensils.remove("fork")
19
+ # print(utensils)
20
+
21
+ # To join two sets together and to save it one of the 2 sets use "update" command
22
+ # utensils.update(dishes)
23
+ # print(utensils)
24
+
25
+ # # To store sum of two sets in third set use 'union' command
26
+ # dinner_table = utensils.union(dishes)
27
+ # # alternative could be : dinner_table = dishes.union(utensils)
28
+ # print(dinner_table)
29
+
30
+ # To find difference b/w two sets use 'difference'
31
+ print (dishes .difference (utensils )) #Compares elements in dishes against utensils
32
+
33
+ # To find common elements b/w two sets use intersection
34
+ print (dishes .intersection (utensils ))
You can’t perform that action at this time.
0 commit comments