forked from mouredev/Hello-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06_sets.py
57 lines (35 loc) · 1.08 KB
/
06_sets.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Clase 4 (24/08/22) en directo desde Twitch: https://www.twitch.tv/videos/1571410092
### Sets ###
# Definición
my_set = set()
my_other_set = {}
print(type(my_set))
print(type(my_other_set)) # Inicialmente es un diccionario
my_other_set = {"Brais","Moure", 35}
print(type(my_other_set))
print(len(my_other_set))
# Inserción
my_other_set.add("MoureDev")
print(my_other_set) # Un set no es una estructura ordenada
my_other_set.add("MoureDev") # Un set no admite repetidos
print(my_other_set)
# Búsqueda
print("Moure" in my_other_set)
print("Mouri" in my_other_set)
# Eliminación
my_other_set.remove("Moure")
print(my_other_set)
my_other_set.clear()
print(len(my_other_set))
del my_other_set
#print(my_other_set) NameError: name 'my_other_set' is not defined
# Transformación
my_set = {"Brais","Moure", 35}
my_list = list(my_set)
print(my_list)
print(my_list[0])
my_other_set = {"Kotlin","Swift", "Python"}
# Otras operaciones
my_new_set = my_set.union(my_other_set)
print(my_new_set.union(my_new_set).union(my_set).union({"JavaScript", "C#"}))
print(my_new_set.difference(my_set))