Re: [Tutor] Keeping Dictonary Entries Ordered

2009-02-14 Thread Wayne Watson
Title: Signature.html It looks like a secondary list should do the trick. I'm not adverse to keeping one. My list is maybe 30-40 items at most. When I posted originally, I was just trying to find if I had overlooked something. It appears that without a secondary list, it gets pretty tricky. A

Re: [Tutor] Keeping Dictonary Entries Ordered

2009-02-13 Thread spir
Le Fri, 13 Feb 2009 15:41:01 +1300, John Fouhy a écrit : > 2009/2/13 Eric Dorsey : > > Alan, can you give a short snippet of what that would look like? I was > > trying to code out some idea of how you'd retain insertion order using > > another dict or a list and didn't get anywhere. > > Here's

Re: [Tutor] Keeping Dictonary Entries Ordered

2009-02-12 Thread John Fouhy
2009/2/13 Eric Dorsey : > Alan, can you give a short snippet of what that would look like? I was > trying to code out some idea of how you'd retain insertion order using > another dict or a list and didn't get anywhere. Here's something basic: class o_dict(dict): def __init__(self, *args, **

Re: [Tutor] Keeping Dictonary Entries Ordered

2009-02-12 Thread Eric Dorsey
But you need to have an order that will work with sorted(). > Its not just the order you add items to the dict. To store an > arbitrary order I suspect you would need to maintain a > secondary list with the keys in the order of insertion. > The most reliable way to dop that would be to subclas

Re: [Tutor] Keeping Dictonary Entries Ordered

2009-02-12 Thread spir
Le Thu, 12 Feb 2009 09:25:22 -, "Alan Gauld" 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

Re: [Tutor] Keeping Dictonary Entries Ordered

2009-02-12 Thread Kent Johnson
On Thu, Feb 12, 2009 at 4:25 AM, Alan Gauld wrote: > Thats tricky! Dictionaries are not sorted and do not retain insertion order. > But you need to have an order that will work with sorted(). > Its not just the order you add items to the dict. To store an > arbitrary order I suspect you would ne

Re: [Tutor] Keeping Dictonary Entries Ordered

2009-02-12 Thread Senthil Kumaran
On Thu, Feb 12, 2009 at 2:55 PM, Alan Gauld wrote: > But you need to have an order that will work with sorted(). > Its not just the order you add items to the dict. And yes algorithmically, there is No Requirement or I should say a good Use Case for a Dict to have sorted keys. More we work with

Re: [Tutor] Keeping Dictonary Entries Ordered

2009-02-12 Thread Alan Gauld
"Eric Dorsey" wrote 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 Thats pretty much a happy coincidence, there is no guarantee that it will work like that

Re: [Tutor] Keeping Dictonary Entries Ordered

2009-02-12 Thread Alan Gauld
"Wayne Watson" wrote 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

Re: [Tutor] Keeping Dictonary Entries Ordered

2009-02-11 Thread Wayne Watson
Looks good. Thanks. Eric Dorsey wrote: >>> 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_t

Re: [Tutor] Keeping Dictonary Entries Ordered

2009-02-11 Thread Eric Dorsey
>>> 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

[Tutor] Keeping Dictonary Entries Ordered

2009-02-11 Thread Wayne Watson
Title: Signature.html 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