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: emphasize iteration volatility for dict
Type: Stage:
Components: Documentation Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: aisaac0, rhettinger
Priority: normal Keywords:

Created on 2007-05-18 15:06 by aisaac0, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg32060 - (view) Author: Alan (aisaac0) Date: 2007-05-18 15:06
In footnote (3) at <URL:http://docs.python.org/lib/typesmapping.html>, delete the first two sentences and substitute:

    Keys and values are listed in an arbitrary order.  This order is indeterminate and generally depends on factors outside the scope of the containing program.  However, if items(), keys(), values(), iteritems(), iterkeys(), and itervalues() are called with no intervening modifications to the dictionary, the lists will directly correspond.

*Justification:* users should not be expected to understand without being told that iteration order depends on factors outside the scope of the containing program.

msg32061 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2007-05-18 23:07
While the OP knows what he means here, the suggested text does not add clarity, it only makes the subject harder to understand and implies that some mysterious, dark force is in place.  Further, the suggested text is simply incorrect.  Given deterministic assignment of hash values and a consistent insertion order, the order of keys in a set or dictionary is fully determined.

I've read the source of this suggestion on comp.lang.python and commented there.  The underlying issue had nothing to do with either sets or dicts.  The code in question "re-discovered" that the location of objects in memory  would vary between runs if the user deleted a pyc file for a module.  The OP's script used object ids as hash values, hence the set/dict ordering could vary between runs.  This was at odds with his expectation that that the ordering would be deterministic.  The moral is that non-deterministic hash values lead to non-deterministic set/dict ordering.

The docs for sets and dicts should not be muddled with tangential discussions about implementation specific details regarding what governs where objects are placed in memory.
History
Date User Action Args
2022-04-11 14:56:24adminsetgithub: 44973
2007-05-18 15:06:26aisaac0create