|
10 | 10 | print(type(my_dict)) |
11 | 11 | print(type(my_other_dict)) |
12 | 12 |
|
13 | | -my_other_dict = {"Nombre": "Brais", |
14 | | - "Apellido": "Moure", "Edad": 35, 1: "Python"} |
| 13 | +my_other_dict = {"Nombre": "Brais", "Apellido": "Moure", "Edad": 35, 1: "Python"} |
15 | 14 |
|
16 | 15 | my_dict = { |
17 | 16 | "Nombre": "Brais", |
18 | 17 | "Apellido": "Moure", |
19 | 18 | "Edad": 35, |
20 | 19 | "Lenguajes": {"Python", "Swift", "Kotlin"}, |
21 | | - 1: 1.77 |
| 20 | + 1: 1.77, |
22 | 21 | } |
23 | 22 |
|
24 | 23 | print(my_other_dict) |
|
27 | 26 | print(len(my_other_dict)) |
28 | 27 | print(len(my_dict)) |
29 | 28 |
|
| 29 | +d = dict() |
| 30 | +print(d) |
| 31 | +print(type(d)) |
| 32 | + |
| 33 | +d = dict({1: "Ramesh", 2: "Suresh", 3: "Mahesh"}) |
| 34 | +print(d) |
| 35 | + |
| 36 | +d = dict([(1, "Ramesh"), (2, "Arjun")]) |
| 37 | +print(d) |
| 38 | + |
| 39 | + |
30 | 40 | # Búsqueda |
31 | 41 |
|
32 | 42 | print(my_dict[1]) |
|
74 | 84 | print(list(dict.fromkeys(list(my_new_dict.values())).keys())) |
75 | 85 | print(tuple(my_new_dict)) |
76 | 86 | print(set(my_new_dict)) |
| 87 | + |
| 88 | +d = {1: "Ramesh", 2: "Suresh", 3: "Mahesh"} |
| 89 | +print("Before clearing dictionary: ", d) |
| 90 | +d.clear() |
| 91 | +print("After cleared entries in dictionary: ", d) |
| 92 | + |
| 93 | +d = {1: "Ramesh", 2: "Suresh", 3: "Mahesh"} |
| 94 | +print("Before delete dictionary: ", d) |
| 95 | +del d |
| 96 | + |
| 97 | +d = dict([(1, "Ramesh"), (2, "Arjun")]) |
| 98 | +print("length of dictionary is: ", len(d)) |
| 99 | + |
| 100 | +d = {1: "Ramesh", 2: "Suresh", 3: "Mahesh"} |
| 101 | +print(d.get(1)) |
| 102 | +print(d.get(100)) |
| 103 | + |
| 104 | +d = {1: "Ramesh", 2: "Suresh", 3: "Mahesh"} |
| 105 | +print(d.get(1)) |
| 106 | +print(d.get(100, "No key found")) |
| 107 | + |
| 108 | +d = {1: "Ramesh", 2: "Suresh", 3: "Mahesh"} |
| 109 | +print("Before pop:", d) |
| 110 | +d.pop(1) |
| 111 | +print("After pop:", d) |
| 112 | + |
| 113 | +# This method removes an arbitrary item(key-value) from the dictionary and returns it. |
| 114 | +d = {1: "Ramesh", 2: "Suresh", 3: "Mahesh"} |
| 115 | +print("Before popitem:", d) |
| 116 | +d.popitem() |
| 117 | +print("After popitem:", d) |
| 118 | + |
| 119 | +d1 = {1: "Ramesh", 2: "Suresh", 3: "Mahesh"} |
| 120 | +d2 = d1.copy() |
| 121 | +print(d1) |
| 122 | +print(d2) |
| 123 | + |
| 124 | +squares = {a: a * a for a in range(1, 6)} |
| 125 | +print(squares) |
0 commit comments