On Nov 23, 6:43 pm, John Machin <[EMAIL PROTECTED]> wrote: > On Nov 24, 11:59 am, Carsten Haese <[EMAIL PROTECTED]> wrote: > > > Diez B. Roggisch wrote: > > > AFAIK the order is deterministic as long as you don't alter the dict > > > between > > > iterations. However, this is an implementation detail. > > > It's not an implementation detail. It's documented behavior. Thus > > quothhttp://docs.python.org/library/stdtypes.html#mapping-types-dict: > > > """ > > If items(), keys(), values(), iteritems(), iterkeys(), and itervalues() > > are called with no intervening modifications to the dictionary, the > > lists will directly correspond. > > """ > > Changing the value attached to an existing key is a "modification to > the dictionary", but it's hard to see how that would change the > iteration order.
Although the referenced docs don't clarify it, changing the value without adding or removing a key (even temporarily) does NOT reorder the dict. This has been declared officially on python-dev. > "the lists will directly correspond"? What does that mean? Why not > "the lists will be equal i.e. list1 == list2"? > > How about "Provided that keys are neither added nor deleted, the order > of iteration will not change"? Python 3.0 never returns lists directly (it provides views), so the wording has already been tweaked. -- http://mail.python.org/mailman/listinfo/python-list