0
En el ejemplo de abajo, no entiendo porqué obtengo False como salida de print(pairs.get(1))
pairs = {"1": "manzana", 2: "dos", 1: "apple", 3: "pera", "orange": [2, 3, 4], True: False, None: "True", } print(pairs.get(1)) print(pairs.get("1")) print(pairs.get(1)) print(pairs.get(2)) print(pairs.get(3)) print(pairs.get("orange")) print(pairs.get(7)) print(pairs.get(12345, "not in dictionary"))
2 Answers
+ 1
This is the problem:
1: "apple",
True: False,
True is evaluated to 1 and as it already exists as a dictionary key, the first value associated to 1, "apple", is overwritten by False.
You can confirm this by printing the whole dictionary:
print(pairs)
{'1': 'manzana', 2: 'dos', 1: False, 3: 'pera', 'orange': [2, 3, 4], None: 'True'}
+ 1
Thanx!!!