Ordered dictionary?

BW Glitch bwglitch at hotpop.com
Thu Jan 22 17:49:54 EST 2004


Leif K-Brooks wrote:

> Josiah Carlson wrote:
> 
>>> I need to associate a string (key) with an integer (value). A 
>>> dictionary would do the job, except for the fact that it must be 
>>> ordered. I also need to look up the value for a specific key easily, 
>>> so a list of tuples wouldn't work.
>>
>>
>>
>> How must the dictionary be ordered?  Do you need the keys or the 
>> values sorted?
> 
> 
> Sorry for not making that clear, I need it sorted by the order of 
> insertion. Looks like 
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747 might do 
> what I want...

That should do. Looks promising, but I think it uses the old style of 
extending the dictionary (Not that it's bad) ...

-- 
Glitch

http://andres980.tripod.com/

One good shot is worth a hundred bad ones!
         -- Big Shot (G1)



More information about the Python-list mailing list