pocet_piv = { 'Petr' : 6 , 'Pavel' : 7, 'Martin': 4}
for whatever in pocet_piv:
print(whatever, pocet_piv[whatever])
I would expect that pocet_piv[whatever] brings me a key from the dictionary, not the value. Who devised the logic for it to come up with the value, and why?
Yup, if whatever is already the key so print(pocet_piv[whatever]) would print the key in pocet_piv dictionary. So the question is, how was born the logic it prints the value.
Keys in dictionary are similar to indexes in ordered sequences differences being that keys can be arbitrary hashable values whether indexes are sequential integers starting from zero.
items = ['bacon', 'ham', 'spam']
items[0]
# should it return 0 or 'bacon'?
# if 'bacon' why should dictionary keys be different?
# if 0 then how 'bacon' is accessible?