-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset.py
More file actions
48 lines (34 loc) · 704 Bytes
/
Copy pathset.py
File metadata and controls
48 lines (34 loc) · 704 Bytes
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
#set is an unordered, mutable, unique collection
#set example
myset = {1, 2, 3, 3, 4}
print(myset)
#no indexing in sets
myset = {10, 20, 30}
# myset[0] ❌ Not allowed
#set manipulation
#add element
myset.add(50)
#update multiple elements
myset.update([60, 70])
#remove element(throws error if missing)
myset.remove(20)
#discard element(safe)
myset.discard(100) #no error
#pop(removes random item)
myset.pop()
#clear set
myset.clear()
#set operations
#set theory operations
#union
a = {1, 2, 3}
b = {3, 4, 5}
print(a | b )
#intersection i.e The operator & keeps only elements that appear in both sets.
print(a & b)
# {3}
#difference
print(a - b)
#{1, 2}
#symmetric difference
print(a ^ b)