Non-deterministic set ordering

Rob Cliffe rob.cliffe at btinternet.com
Sun May 15 23:01:10 EDT 2022


I was shocked to discover that when repeatedly running the following 
program (condensed from a "real" program) under Python 3.8.3

for p in { ('x','y'), ('y','x') }:
     print(p)

the output was sometimes

('y', 'x')
('x', 'y')

and sometimes

('x', 'y')
('y', 'x')

Can anyone explain why running identical code should result in 
traversing a set in a different order?
Thanks
Rob Cliffe


More information about the Python-list mailing list