An ordered dictionary for the Python library?

M

Mark Summerfield

I must think the API good because I have been implementing, in parallel
with this discussion, my own "OrderedDict" with a very similar API (this
is part of a larger project where I recently found the need to have a
well-implemented ordered dict). The only real omission I see is to allow
instantiating a "sorted dict" with an optional cmp function--to allow
the generalization of such features as case-independence, etc.

I tend to create different orderings by munging the keys rather than
by having optional cmp functions (as you'll see in the sorteddict.py
docstring). I've now put sorteddict on PyPI (with docs & tests):
http://pypi.python.org/pypi/sorteddict

I'm going offline for a week, so I'll see if there's any consensus or
progress when I'm back online, and then decide whether to do a PEP or
not.
 
D

Diez B. Roggisch

Mark said:
I tend to create different orderings by munging the keys rather than
by having optional cmp functions (as you'll see in the sorteddict.py
docstring). I've now put sorteddict on PyPI (with docs & tests):
http://pypi.python.org/pypi/sorteddict

The advantage of a passed cmp-function is that the context of usage
hasn't to be aware of any change in semantics. Yet for better
performance, the cmp-function might be a tad to slow, better use a
key-function like for sorted/sort.

Additionally, I'd change the parameter names of the keys()-method to
start/end and make more clear if end is inclusive or not. The
first/secondindex-names are pretty horrible IMHO, because the
essentially enumerate parameters. Who wants to work with a method

foo(arg1, arg2, arg3)

? :)

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
BrentonMcc
Top