Mercurial > cpython-lru_cache-weakref
diff Doc/lib/libstdtypes.tex @ 24903:ecd4ada252bc 2.2
Extend some comments on the order of values in the returns from
dict.items/keys/values/iteritems/iterkeys/itervalues().
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Mon, 19 Aug 2002 22:01:19 +0000 |
| parents | f6a97cd3ba24 |
| children | dae2282bc76b |
line wrap: on
line diff
--- a/Doc/lib/libstdtypes.tex Mon Aug 19 01:20:09 2002 +0000 +++ b/Doc/lib/libstdtypes.tex Mon Aug 19 22:01:19 2002 +0000 @@ -1022,13 +1022,13 @@ {(6)} \lineiii{\var{a}.iteritems()} {return an iterator over (\var{key}, \var{value}) pairs} - {(2)} + {(2), (3)} \lineiii{\var{a}.iterkeys()} {return an iterator over the mapping's keys} - {(2)} + {(2), (3)} \lineiii{\var{a}.itervalues()} {return an iterator over the mapping's values} - {(2)} + {(2), (3)} \end{tableiii} \noindent @@ -1040,11 +1040,17 @@ \item[(2)] \versionadded{2.2} \item[(3)] Keys and values are listed in random order. If -\method{keys()} and \method{values()} are called with no intervening -modifications to the dictionary, the two lists will directly -correspond. This allows the creation of \code{(\var{value}, -\var{key})} pairs using \function{zip()}: \samp{pairs = -zip(\var{a}.values(), \var{a}.keys())}. +\method{items()}, \method{keys()}, \method{values()}, +\method{iteritems()}, \method{iterkeys()}, and \method{itervalues()} +are called with no intervening modifications to the dictionary, the +lists will directly correspond. This allows the creation of +\code{(\var{value}, \var{key})} pairs using \function{zip()}: +\samp{pairs = zip(\var{a}.values(), \var{a}.keys())}. The same +relationship holds for the \method{iterkeys()} and +\method{itervalues()} methods: \samp{pairs = zip(\var{a}.itervalues(), +\var{a}.iterkeys())} provides the same value for \code{pairs}. +Another way to create the same list is \samp{pairs = [(v, k) for (k, +v) in \var{a}.iteritems()]}. \item[(4)] Never raises an exception if \var{k} is not in the map, instead it returns \var{x}. \var{x} is optional; when \var{x} is not
