Le Thu, 12 Feb 2009 09:25:22 -0000,
"Alan Gauld" <[email protected]> a écrit :

> > config_names = {"start_time : '18:00:00', 'gray_scale' : True, 
> > "long": 120.00}
> >
> > If I iterate over it, the entries will appear in any order, as 
> > opposed to
> > what I see above. However, in the config file, I'd like to keep them
> > in the order above.  
> 
> Thats tricky! Dictionaries are not sorted and do not retain insertion 
> order.

Had to do something similar.
I just subtyped dict to add a separate list a keys. Initiated with the possible 
initial arguments, then updated by setattr. Very few code lines. Then Ordict 
had a simplissim method to return values (and pairs) the keylist's order.
The only issue was rather a semantic one: should a value change keep the 
keylist unchanged or move the key to the last position?

Denis

------
la vida e estranya
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to