0
["one", "two", "three", "four"]
numbers = ["one", "two", "three", "four"] num_dict = {x[0]: x for x in numbers} print(num_dict["t"]) OUTPUT: three #print(num_dict["t"])? One, two and three are all strings in a list? What does "t" denote? It cannot be strings that start with "t" because then two would print as well and it cannot be the third index because that would be "four". Any ideas? Thanks as always.
1 Answer
+ 2
print(num_dict)
# {'o': 'one', 't': 'three', 'f': 'four'}
Duplicate keys are not allowed in dictionaries. When you asign a value to an already exisiting key it doesn't add it to the dictionary, but replaces the existing value.
If the original list was ["one", "three", "two", "four"] then num_dict["t"] would be "two" as it would override "three".



