-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet_Demo.py
More file actions
58 lines (40 loc) · 1.22 KB
/
Set_Demo.py
File metadata and controls
58 lines (40 loc) · 1.22 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'''
python set is unordered collection with no duplicate elements
python set can be declared in 2 different ways
{} and using set() functions
'''
#basket={'apple','orange','pear','apple','guava'}
#print(basket)
#print('orange' in basket)
#set is mutable and slicing is not possible as there are no fixed index
#sampleWord='umbrella'
#print(set(sampleWord))
flowers={"sunflowers","roses","lavender","tulips","goldcrest","lotus"}
indian_Flowers={"hibiscus","lotus","pinwheelflower"}
indian_Flowers.add("marigold")
print(indian_Flowers)
#set difference
print(indian_Flowers.difference(flowers))
#Intersection Operator
print(indian_Flowers.intersection(flowers))
print(indian_Flowers.isdisjoint(flowers))
print(indian_Flowers.issuperset(flowers))
print(indian_Flowers.issubset(flowers))
#symmetric difference
print(flowers.symmetric_difference(indian_Flowers))
print(flowers.union(indian_Flowers))
flowers.update(indian_Flowers)
print(flowers)
flowers.discard("roses")
print(flowers)
print(flowers.pop())
print(flowers)
flowers.clear()
print(flowers)
x=set()
print(type(x))
#frozenset is same as set
fs=frozenset(["g","o","o","d"])
print(fs)
#fs.pop()
#print(fs)