This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Dictionary ordering docs are too unclear of dangers
Type: Stage:
Components: Documentation Versions:
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: ironfroggy, loewis, sf-robot, tim.peters
Priority: normal Keywords:

Created on 2006-12-09 11:57 by ironfroggy, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg30771 - (view) Author: Calvin Spealman (ironfroggy) Date: 2006-12-09 11:57
The footnote #3 on this page of the documentation details some thoughts on the order of dictionaries and the results of the different key and value retreival methods. I think it promises more than it should. The current content tells the reader they can expect consistant results from a dictionary as far as order goes, and we know this to be simply untrue and even in the circumstances where its likely (but still not impossible), such as `zip(d.values(), d.keys())` there is not even any compelling reason to use such odd methods, making the very fact that the idea is documented suspect.

I recommend the footnote be removed entirely, or replaced with "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. Do not expect anything of the order of the items(), keys(), values(), iteritems(), iterkeys(), and itervalues() methods' results." 


Page in question:
http://docs.python.org/lib/typesmapping.html
msg30772 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-12-09 14:31
You seem to be saying (without actually saying it) that the footnote is untrue. Can you give an example that demonstrates it is untrue?

I believe the footnote is correct, precise, and complete as it stands, and fail to see a bug here.
msg30773 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2006-12-09 14:51
The statement that the various ways of extracting info from a dict are consistent /provided that/ they're "called with no intervening modifications to the dictionary" (did you miss that crucial qualification?) is part of the language definition:  it definitely and deliberately constrains the set of possible implementations.

The docs didn't originally say this, but people noted it was true in then-current CPython, and asked whether they could rely on it.  At that point, Guido decided to elevate this property of the CPython implementation to a language requirement, and the footnote was added.

Of course you're not /required/ to rely on it ;-).
msg30774 - (view) Author: SourceForge Robot (sf-robot) Date: 2006-12-24 03:20
This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).
msg30775 - (view) Author: Calvin Spealman (ironfroggy) Date: 2006-12-24 16:27
This would only fail with the use of threads or weakref callbacks, most likely. I still think thats enough reason to take them back out. Assuring any order at any time, reguardless of the circumstances, I feel, is just against the concept of the dictionary.
msg30776 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-12-29 22:03
It can't fail just because of the presence of threads or weakref callbacks, unless these perform modifications to the dictionary. Such modifications can, of course, also happen in a regular loop, if the code in the loop performs the modification (either directly or indirectly, through function calls).

As Tim says: if it hurts your feelings to make such an assumption, then just don't make it for yourself (i.e. don't rely on it in your own programs).
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44320
2006-12-09 11:57:24ironfroggycreate