If I have two identical sets, meaning a == b gives me True, will they have the same iteration order? I tried it, and it works:
>>> foo = set("abc")
>>> bar = set("abc")
>>> zip(foo, bar)
[('a', 'a'), ('c', 'c'), ('b', 'b')]
My question is, was I lucky, or is this behavior guaranteed?
It wasn’t just a coincidence that they came out the same: the implementation happens to be deterministic, so creating the same set twice produces the same ordering. But Python does not guarantee that.
If you create the same set in two different ways:
…you can get different ordering: