dictionary: keys() and values()
Andrew Koenig
ark at research.att.com
Thu Jun 13 15:33:34 EDT 2002
John> keys = m.keys()
John> values = m.values()
John> Do we know if the values come out in the same order, that is does
John> m[keys[i]] necessarily equal values[i] ?
>From the library reference, 2.2.7, footnote 3:
If keys() and values() are called with no intervening modifications to the
dictionary, the two lists will directly correspond. This allows the creation
of (value, key) pairs using zip(): "pairs = zip(a.values(), a.keys())".
--
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
More information about the Python-list
mailing list