forked from mouredev/Hello-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07_dicts.py
75 lines (52 loc) · 1.36 KB
/
07_dicts.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Clase 4 (24/08/22) en directo desde Twitch: https://www.twitch.tv/videos/1571410092
### Dictionaries ###
# Definición
my_dict = dict()
my_other_dict = {}
print(type(my_dict))
print(type(my_other_dict))
my_other_dict = {"Nombre":"Brais", "Apellido":"Moure", "Edad":35, 1:"Python"}
my_dict = {
"Nombre":"Brais",
"Apellido":"Moure",
"Edad":35,
"Lenguajes": {"Python","Swift", "Kotlin"},
1:1.77
}
print(my_other_dict)
print(my_dict)
print(len(my_other_dict))
print(len(my_dict))
# Búsqueda
print(my_dict[1])
print(my_dict["Nombre"])
print("Moure" in my_dict)
print("Apellido" in my_dict)
# Inserción
my_dict["Calle"] = "Calle MoureDev"
print(my_dict)
# Actualización
my_dict["Nombre"] = "Pedro"
print(my_dict["Nombre"])
# Eliminación
del my_dict["Calle"]
print(my_dict)
# Otras operaciones
print(my_dict.items())
print(my_dict.keys())
print(my_dict.values())
my_list = ["Nombre", 1, "Piso"]
my_new_dict = dict.fromkeys((my_list))
print(my_new_dict)
my_new_dict = dict.fromkeys(("Nombre", 1, "Piso"))
print((my_new_dict))
my_new_dict = dict.fromkeys(my_dict)
print((my_new_dict))
my_new_dict = dict.fromkeys(my_dict, "MoureDev")
print((my_new_dict))
my_values = my_new_dict.values()
print(type(my_values))
print(my_new_dict.values())
print(list(dict.fromkeys(list(my_new_dict.values())).keys()))
print(tuple(my_new_dict))
print(set(my_new_dict))