A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-January/075877.html below:

[Python-Dev] Repeatability of looping over dicts

[Python-Dev] Repeatability of looping over dictsTim Delaney timothy.c.delaney at gmail.com
Fri Jan 4 21:05:55 CET 2008
A.M. Kuchling wrote:

> So, do Python implementations need to guarantee that list(dict_var) ==
> a later result from list(dict_var)?

As I just posted to the blog, yes. Look at section 3.8 of the reference 
manual
(Mapping Types), specifically footnote 3:

http://docs.python.org/lib/typesmapping.html

(3) 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 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(a.values(), a.keys())". The same relationship holds for the
iterkeys() and 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()]".

Tim Delaney 

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4