[Tutor] Keeping Dictonary Entries Ordered
Eric Dorsey
dorseye at gmail.com
Thu Feb 12 04:26:47 CET 2009
>>> config_names = {'start_time': '18:00:00', 'gray_scale': True, 'long':
120.0}
>>> config_names
{'start_time': '18:00:00', 'gray_scale': True, 'long': 120.0}
>>> for i, x in config_names.items():
... print i, x
...
start_time 18:00:00
gray_scale True
long 120.0
>>>
On Wed, Feb 11, 2009 at 7:48 PM, Wayne Watson
<sierra_mtnview at sbcglobal.net>wrote:
> I have a dictionary that looks like:
>
> 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. That I want to write the config file in order. Perhaps, I need
> a list like c_names = ["start_time", "gray_scale", "long"] to get the keys
> out in the order I need? Maybe there's another way?
> --
>
> Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>
> (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)
>
> *The Richard Feynman Problem-Solving Algorithm:*
> * (1) write down the problem;*
> * (2) think very hard;*
> * (3) write down the answer.***
> **
>
> ****** Web Page: <www.speckledwithstars.net/>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090211/e6639a58/attachment.htm>
More information about the Tutor
mailing list