dict.keys() and dict.values() are always the same order, is it?

alex23 wuwei23 at gmail.com
Wed Apr 21 06:37:55 CEST 2010


Steven D'Aprano <ste... at REMOVE.THIS.cybersource.com.au> wrote:
> if you don't trust the language to behave
> correctly in this case:
>
> pairs = zip(d.values(), d.items())
>
> what makes you think you can trust d.iteritems(), list comprehensions, or
> even tuple packing and unpacking?

Because .iteritems() is an atomic operation while the .values/.items
approach is two independent calls. That the former binds the two
together in its implementation makes sense, that two _independent_
methods are bound feels far more like magic.





More information about the Python-list mailing list