-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsets.py
More file actions
42 lines (26 loc) · 1.01 KB
/
Copy pathsets.py
File metadata and controls
42 lines (26 loc) · 1.01 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
# Creating sets
set_a = {1, 2, 3, 4}
set_b = {3, 4, 5, 6}
# Add Item
set_a.add(5)
# remove Item
set_a.remove(3)
# discard Item
set_a.discard(4)
popped_item = set_a.pop()
print(f"Popped item: {popped_item}") # Output: Popped item: (could be 1, 2, or 5 depending on the internal order)
print(set_a) # Remaining items after popping
# clear() "Clears all the items in the set"
#set_a.clear()
# union(another_Set)
union_set = set_a.union(set_b)
print(union_set)
# intersection(another_set)
intersection_set = set_a.intersection(set_b)
print(intersection_set) # Output: {5}
# difference(other_set) "Returns a new set with items in the first set but not in the second."
difference_set = set_a.difference(set_b) # current sets are set_a = {2,5} and set_b = {3, 4, 5, 6}
print(difference_set)
# symmetric_difference(other_set) "Returns a new set with items in either set but not in both."
sym_diff_set = set_a.symmetric_difference(set_b) # current sets are set_a = {2,5} and set_b = {3, 4, 5, 6}
print(sym_diff_set)