-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5. sets.py
43 lines (32 loc) · 1.18 KB
/
5. sets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#sets are evalues that are unordered and also have no duplicate
cs_course = {'math', 'chemistry', 'computer', 'physics'}
print(cs_course)
#outcome has different order of list which we have entered. it is because the order doesnt matter to cs_s
#and cs_s are generally used to remove duplicates and find wether the item is present in list or not
cs_course = {'math', 'math', 'chemistry', 'computer', 'physics'}
print(cs_course)
#to find presence of item
print('math' in cs_course)
#to find intersection
cs_course = {'math', 'chemistry', 'computer', 'physics'}
art_course = {'art', 'chemistry', 'design', 'physics'}
print(cs_course.intersection(art_course))
#to find difference
cs_course = {'math', 'chemistry', 'computer', 'physics'}
art_course = {'art', 'chemistry', 'design', 'physics'}
print(cs_course.difference(art_course))
#to find union
cs_course = {'math', 'chemistry', 'computer', 'physics'}
art_course = {'art', 'chemistry', 'design', 'physics'}
print(cs_course.union(art_course))
#empty list
list1 =[]
list1 = list()
#empty tuple
tuple1 = ()
tuple1 = tuple()
#empty sets
set1 = {}#this isn't right! it's a dictionary
set1 = set()
#to remove elements from a set
cs_course.discard('maths')