[Python-ideas] issubclass(collections.OrderedDict, collections.Sequence)

Guido van Rossum guido at python.org
Sun Oct 5 22:53:10 CEST 2014


On Sun, Oct 5, 2014 at 11:40 AM, Ram Rachum <ram at rachum.com> wrote:

> I was just going to test whether a mapping is dict-like or an
> OrderedDict-like object by doing this:
>
>     isinstance(x, collections.Sequence)
>
> But then I checked and saw that this is False:
>
>     issubclass(collections.OrderedDict, collections.Sequence) is False
>
> Why isn't an OrderedDict a Sequence?
>

Check the interface of Sequence. It requires indexing behavior that
OrdedDict doesn't have -- a[i] is a key lookup in the underlying dict, not
an indexed lookup in the ordered list of elements. I don't think it would
be wise to attempt to add that behavior either (given that the keys may
well be integers).

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141005/d1a312b7/attachment.html>


More information about the Python-ideas mailing list