Keys must be unique in a dictionary, but I typed in the following assignment statement and it worked:
test = {'A1': 12, 'A1': 13, 'A1': 14}
and then testing it, I found
test['A1']
14
My question is: will dictionaries with the same key repeated multiple times choose the last occurring instance of that key when called? (i.e. Do the entries override each other)
In Python, Dictionary storage is very interesting. Internally dictionaries are implemented using hash tables. So when you initialise a dictionary , these are the following steps that takes place in the background:
Nice explanation for Python dictionary implementation http://www.laurentluce.com/posts/python-dictionary-implementation/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With