Dictionary sorting
Ben Finney
ben+python at benfinney.id.au
Fri Nov 4 08:19:25 EDT 2011
Hrvoje Niksic <hniksic at xemacs.org> writes:
> Ben Finney <ben+python at benfinney.id.au> writes:
>
> > Tim Chase <python.list at tim.thechases.com> writes:
> >> Does this "never trust it" hold even for two consecutive iterations
> >> over an unchanged dict? I didn't see anything in the docs[1] to make
> >> such a claim,
> >
> > Exactly.
>
> This is false. The docs say:
>
> If items(), keys(), values(), iteritems(), iterkeys(), and
> 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(d.values(),
> d.keys()).
>
> (http://docs.python.org/library/stdtypes.html#mapping-types-dict)
Thank you for this correction.
--
\ “Firmness in decision is often merely a form of stupidity. It |
`\ indicates an inability to think the same thing out twice.” |
_o__) —Henry L. Mencken |
Ben Finney
More information about the Python-list
mailing list