forked from MorvanZhou/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
35_set.py
29 lines (21 loc) · 757 Bytes
/
35_set.py
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
# View more python learning tutorial on my Youtube and Youku channel!!!
# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
# Youku video tutorial: http://i.youku.com/pythontutorial
char_list = ['a', 'b', 'c', 'c', 'd', 'd', 'd']
sentence = 'Welcome Back to This Tutorial'
print(set(char_list))
print(set(sentence))
print(set(char_list + list(sentence)))
unique_char = set(char_list)
unique_char.add('x')
# unique_char.add(['y', 'z']) this is wrong
print(unique_char)
unique_char.remove('x')
print(unique_char)
unique_char.discard('d')
print(unique_char)
unique_char.clear()
print(unique_char)
unique_char = set(char_list)
print(unique_char.difference({'a', 'e', 'i'}))
print(unique_char.intersection({'a', 'e', 'i'}))