[Python-ideas] Indicate if an iterable is ordered or not

Nick Coghlan ncoghlan at gmail.com
Wed Sep 25 01:01:47 CEST 2013


On 25 Sep 2013 02:24, "Guido van Rossum" <guido at python.org> wrote:
>
> What do you want to do with this knowledge?

My reaction is the same as Guido's.

There's already an implicit expectation that iterables will be *consistent*
in the absence of mutation (i.e.  arbitrarily ordered rather than
unordered), but I don't see how "ordered based on container internal
details" is meaningfully different from "ordered by some external
criterion".

Cheers,
Nick.

>
> On Tue, Sep 24, 2013 at 9:15 AM, Eric Snow <ericsnowcurrently at gmail.com>
wrote:
> > Iterables are not necessarily ordered (e.g. dict vs. OrderedDict).
> > Sequences are but Sets aren't.  I'm not aware of any good way
> > currently to know if an arbitrary iterable is ordered.  Without an
> > explicit indicator of ordered-ness, you must know in advance for each
> > specific type.
> >
> > One possible solution is an __isordered__ attribute (on the class),
> > set to a boolean.  The absence of the attribute would imply False.
> >
> > Such an attribute would be added to existing types:
> >
> > * collections.abc.Iterable (default: False)
> > * list (True)
> > * tuple (True)
> > * set (False)
> > * dict (False)
> > * collections.OrderedDict (True)
> > * ...
> >
> > Thoughts?
> >
> > -eric
> > _______________________________________________
> > Python-ideas mailing list
> > Python-ideas at python.org
> > https://mail.python.org/mailman/listinfo/python-ideas
>
>
>
> --
> --Guido van Rossum (python.org/~guido)
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130925/d17d53f1/attachment.html>


More information about the Python-ideas mailing list