- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path013_sets.py
More file actions
Latest commit
32 lines (23 loc) · 660 Bytes
/
Copy path013_sets.py
File metadata and controls
32 lines (23 loc) · 660 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
# a set is a list that is unordered
# only has unique values
# while values can change
# those values themselves
# must be immutable
first_set=set(["John", 1])
second_set= {"Paul", 1}
print("Length: ", len(second_set))
# union
third_set=first_set|second_set# join sets
print(third_set)
third_set.add("Doug")
third_set.discard("John")
# remove random value
print("Random", third_set.pop())
#
third_set|=second_set
print(first_set.intersection(second_set))
print(first_set.symmetric_difference(second_set))
print(first_set.difference(second_set))
third_set.clear()
# frozen set # cant be change in any way
fourth_set=frozenset(["Paul", 7])