It's blowing my mind a little bit that OrderedDict in Python is not a sequence type. It has a concept of order, but it's not a sequence.
The Python docs say
There are seven sequence types: strings, Unicode strings, lists, tuples, bytearrays, buffers, and xrange objects.
For other containers see the built in dict and set classes, and the collections module. ...Most sequence types support the following operations....Sequence types also support comparisons.
Those operations corresponding to __contains__
, __add__
for concatenation, __getitem__
with integers (in range(len(foo))
), __len__
, __min__
, __slice__
, index
and count
. __lt__
etc implement comparisons.
OrderedDicts implement some of these methods but not others, probably because the syntactic sugar for accessing items by key (as in dict) or order (as in index) is the same.
I know if something implements __iter__
I can loop through it. How can I definitely know if something has an order? I would have thought that is what is meant by "sequence", the nth item is always the nth item.