An ordered dictionary for the Python library?

Antoon Pardon apardon at forel.vub.ac.be
Thu Sep 13 03:06:45 EDT 2007


On 2007-09-12, Mark Summerfield <m.n.summerfield at googlemail.com> wrote:
> On 12 Sep, 13:46, Michele Simionato <michele.simion... at gmail.com>
> wrote:
>> On Sep 12, 2:42 pm, Steven D'Aprano <st... at REMOVE-THIS-
>>
>> cybersource.com.au> wrote:
>> > On Wed, 12 Sep 2007 07:33:45 +0000, Mark Summerfield wrote:
>> > In fact, I'm not sure what people mean by ordered dicts. I assume they
>> > mean the keys are ordered, not the values. But ordered by what? Insertion
>> > order? Modification order? Alphabetical order?
>>
>> Insertion order.
>>
>>  M.S.
>
>
> Actually I meant by key order, so insertion order doesn't matter at
> all. If you need a dictionary-like data structure that respects
> insertion order you could use a list of (key, value) tuples.

If you want a dictionary that iterates over his keys and does so
in a sorted manner you probably want a tree.

One posible implemenation can be found here:

  http://www.pardon-sleeuwaegen.be/antoon/avltree.html


I hope it is usefull to you.

-- 
Antoon Pardon



More information about the Python-list mailing list