On Tue, 5 Jul 2016 06:36 pm, Peter Otten wrote: > It looks like > > $ python3 -c 'print({1, 2})' > {1, 2} > $ python3 -c 'print({2, 1})' > {1, 2} > > will always print the same output. Can you construct a set from two small > integers where this is not the case? What's the difference?
Define "small". According to some mathematicians, any number you can write down counts as small :-) > What happens if you replace the ints with strings? Why? Depends on the version of Python. Recent versions have hash randomisation turned on, so the order of identical sets/dicts running in identical code will vary from one run to another. [steve@ando 3.6]$ ./python -c "print({'a', 'b', 'c', 'd'})" {'c', 'b', 'd', 'a'} [steve@ando 3.6]$ ./python -c "print({'a', 'b', 'c', 'd'})" {'b', 'c', 'a', 'd'} [steve@ando 3.6]$ ./python -c "print({'a', 'b', 'c', 'd'})" {'c', 'a', 'd', 'b'} -- Steven “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list