[Tutor] Why is an OrderedDict not sliceable?

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Jan 25 07:27:57 EST 2016


On 24 January 2016 at 20:29, Albert-Jan Roskam <sjeik_appie at hotmail.com> wrote:
>> I guess that the authors of OrderedDict just didn't really consider
>> this to be very useful. Apart from having ordered iteration
>> OrderedDict is not really that deeply thought out. There's a thread on
>> python-ideas about the inconsistent behaviour of the keys and values
>> views and equality comparison of OrderedDicts on python-ideas at the
>> moment:
>>
>> https://mail.python.org/pipermail/python-ideas/2015-December/037472.html
>
> As I said in a prior email: That is SCARY! Should I just avoid OrderedDict
> like the plague?

No, OrderedDict works fine. Just in answer to your question about why
this particular feature isn't there:

1) The slicing thing is conceptually not that well defined. To me it
was obvious what you meant but I suspect that many people would find
it confusing or unexpected. (see e.g. the initial responses from Steve
and Ben in this thread)
2) The OrderedDict isn't really that deeply thought out beyond "I want
a dict that has a consistent iteration order".

--
Oscar


More information about the Tutor mailing list