[Python-Dev] Repeatability of looping over dicts

Raymond Hettinger python at rcn.com
Sat Jan 5 01:30:26 CET 2008


>> ConcurrentHashMap scales better in the face of threading 
 .. .
>> So, do Python implementations need to guarantee that list(dict_var) ==
>> a later result from list(dict_var)?

> What code would break if we loosened this restriction? 

I can imagine someone has code like this:
  
   for k in d:
       print '%5s' % k
   for k in d:
       print '-----'
   for v in d.values():
       print '%5s' % v

It seems likely to me that a lot of code using d.values() would care about the order of the values and the only order that matters is corresponding to some set of keys.  There are probably a lot of functions that take keys and values separately, so it would not be uncommon to call those with a pattern like: save_config(configfile, d.keys(), d.values()).

In the OP's context where multiple threads are running, it may be fair to say that all bets are off.


Raymond



More information about the Python-Dev mailing list