<div dir="ltr"><div>Can I ask you to mathematically define the property you are looking for here? In some other languages "Ordered" refers to being sorted or sortable, but the use of this word in OrderedDict does not refer to that at all.<br><br>I tried coming up with a definition, but I got stuck with the rather vague "insertion order is preserved".<br><br>Unfortunately, for the other collection types that (presumably) would qualify for this predicate, like list and tuple, the "insertion" operation is spelled differently than for OrderedDict -- OrderedDict's rule seems to be "new elements inserted with __setitem__ are appended to the end of the underlying sequence", while for list you'd have to write something about the insert() and append() methods (plus other operations like slice assignment and extend() that can be reduced to these), and for tuple you'd have to refer to the constructor.<br><br></div>I don't think that definition is sufficiently crisp and reusable to warrant defining a collection ABC for it. But perhaps you can come up with a better specification for your proposed collections.Ordered ABC?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 5, 2014 at 1:56 PM, Ram Rachum <span dir="ltr"><<a href="mailto:ram@rachum.com" target="_blank">ram@rachum.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Ok, makes sense. Though it still would be nice to have a general way to check whether a collection is ordered or not, regardless of index access. Perhaps a `collections.Ordered`?<div><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 5, 2014 at 11:53 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>On Sun, Oct 5, 2014 at 11:40 AM, Ram Rachum <span dir="ltr"><<a href="mailto:ram@rachum.com" target="_blank">ram@rachum.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div>I was just going to test whether a mapping is dict-like or an OrderedDict-like object by doing this: </div><div><br></div><div> isinstance(x, collections.Sequence)</div><div><br></div><div>But then I checked and saw that this is False:</div><div><br></div><div> issubclass(collections.OrderedDict, collections.Sequence) is False</div><div><br></div><div>Why isn't an OrderedDict a Sequence?</div></div></blockquote><div> <br></div></div></div><div>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).<span><font color="#888888"><br></font></span></div></div><span><font color="#888888"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)
</font></span></div></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br><br clear="all"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)
</div>