[Python-Dev] Proposal: add odict to collections

"Martin v. Löwis" martin at v.loewis.de
Sun Jun 15 09:41:32 CEST 2008

> I compared multiple ordered dicts now (including Babel, Django and the
> C-implementation I mentioned earlier) and implemented a python version
> of the ordered dict as reference implementation:
>    http://dev.pocoo.org/hg/sandbox/raw-file/tip/odict.py

I find the slicing API surprising. IMO, if you do support slicing, then
a) the start and end indices should be the same ones that you also use
   in regular indexing.
b) the result should be of the same kind as the thing being sliced, i.e.
   an odict.

So I would rather expect

>>> d['c':'spam']
odict.odict([('c', 'd'), ('foo', 'bar')])

The slicing operation that you provide should be spelled as
d.items()[1:3], or, if you don't want to pay the cost of creating
the full items list, then add a method such as d.slice_by_index(1,3).
What's the use case for this operation, anyway?


More information about the Python-Dev mailing list