-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet.py
More file actions
26 lines (21 loc) · 863 Bytes
/
Copy pathSet.py
File metadata and controls
26 lines (21 loc) · 863 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
# set does not allow duplicate values
languages = {'html', 'java', 'python'}
# remove - removes the specified value from the set
languages.remove('java')
print(languages)
# pop - removes the first element in the set
languages.pop()
print(languages)
# difference - retuns elements found in the first set and not in the second set
x = {"apple", "banana", "cherry", "facebook"}
y = {"google", "microsoft", "apple", "facebook"}
z = x.difference(y)
print(z)
# symmetric_difference() - returns a set that contains all items from both sets, but not the items that are present in both sets
m = {"apple", "banana", "cherry"}
n = {"google", "microsoft", "apple"}
k = m.symmetric_difference(n)
print(k)
# union - returns a set that contains all items from both sets, where an element exists in both sets, it will only appear once in the new set
z=m.union(n)
print(z)