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()]”.

 

A Django site. this page was rendered by a django application in 0.01s 2010-09-02 15:19:57.925744. hosted by webfaction.