It looks like the lists returned by the keys()
and values()
methods of a dictionary are always a 1-to-1 mapping (assuming the dictionary is not altered between calling the two methods).
For example:
>>> d = {'one': 1, 'two': 2, 'three': 3}
>>> k, v = list(d.keys()), list(d.values())
>>> for i in range(len(k)):
... print(d[k[i]] == v[i])
...
True
True
True
If you do not alter the dictionary between calling keys()
and calling values()
, is it wrong to assume the above for-loop will always print True?