Is there a canonical way to check whether an iterable is ordered?
steve+comp.lang.python at pearwood.info
Fri Sep 19 13:46:01 CEST 2014
Chris Angelico wrote:
> On Fri, Sep 19, 2014 at 8:59 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> Here's a proof of concept of what would be allowed:
> Also, this can't possibly offer the same guarantee. Watch:
> d = MyDict(some_lot_of_items)
> d.values(); d.items()
> # mutate the dict in whatever way you like
> pairs = zip(d.keys(), d.values())
> This might well create mismatched pairs, because after generating the
> keys() return value, the list gets shuffled, prior to generating
> values() in the same expression. This would not be allowed.
That would be a bug, and an easy one to fix. Every mutation of the dict
would have to reset the internal flags back to the starting state.
More information about the Python-list