sorteddict PEP proposal [started off as orderedict]

Antoon Pardon apardon at forel.vub.ac.be
Thu Sep 27 08:49:31 CEST 2007


On 2007-09-26, Mark Summerfield <m.n.summerfield at googlemail.com> wrote:
> On 26 Sep, 13:22, Antoon Pardon <apar... at forel.vub.ac.be> wrote:
>>
>> Well you should decide what you want. In a previous exchange one of the
>> things that was wanted was that you could already seed a tree by using
>> key word arguments so that you could do the following:
>>
>> t=Tree(a=15, b=30)
>>
>> which would be equivallent to:
>>
>> t=Tree()
>> t.update(a=15,b=30)
>>
>> But with the above proposal
>>
>> t=Tree(cmp=cmp)
>>
>> is not equivallent to
>>
>> t=Tree()
>> t.update(cmp=cmp)
>>
>> So it seems the API needs some more sorting out.
>
> I think you missed some of the previous postings.

That is possible.
>
> The sorteddict API that has emerged so far is (1) apart from the
> constructor, everything is identical to dict, (2) the constructor
> takes the same args as sorted(), so if you want to seed with a dict or
> with keywords you write sorteddict(dict(a=1,b=2), ...), (or you could
> create a sorteddict and use update() since that takes the same args as
> dict's constructor).
>
> Could your AVLTree support cmp and keys and reverse?

It already supports cmp. Although for the moment it is done by
subclassing. Like the following.

class myTree(AVLTree):
  @staticmethod
  def cmp(a, b);
    return ....

I don't think adding support for keys will be difficult but it may be
tedious.

I would prefer not to support reverse because the effect can be acquired
by the other two and in contradiction with sorting, I think using it
will slow things down instead of speeding things up.

-- 
Antoon Pardon



More information about the Python-list mailing list