Is there a canonical way to check whether an iterable is ordered?

Chris Angelico rosuav at gmail.com
Fri Sep 19 08:36:59 EDT 2014


On Fri, Sep 19, 2014 at 10:26 PM, alister
<alister.nospam.ware at ntlworld.com> wrote:
> As far as I understand it the order of keys in a dict is not guaranteed
> iterating over the same dict twice (without changes) does not have to
> return the keys in the same order.

The exact guarantee is that you can iterate over keys() followed by
values() and they will correspond. This implies (in the strict logical
sense of the word "implies", as well as the common sense of the same
word) that iterating multiple times over keys() will correspond, which
is the point I drew above.

ChrisA



More information about the Python-list mailing list