We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

dict.items

a.items() a copy of a‘s list of (key, value) pairs.

Keys and values are listed in an arbitrary order which is non-random, varies across Python implementations, and depends on the dictionary’s history of insertions and deletions.

If dict.items, dict.keys, dict.values, dict.iteritems, dict.iterkeys, and dict.itervalues are called with no intervening modifications to the dictionary, the lists will directly correspond. This allows the creation of (value, key) pairs using zip(): “pairs = zip(a.values(), a.keys())”.

The same relationship holds for the dict.iterkeys and dict.itervalues methods: “pairs = zip(a.itervalues(), a.iterkeys())” provides the same value for pairs. Another way to create the same list is “pairs = [(v, k) for (k, v) in a.iteritems()]”.