I am trying to understand python set hashing in detail. I have the following script:
import hashlib
ss = {'a', 'b', 'c', 'd', 'e', 'f', 'g'}
print(ss)
print(hashlib.md5(str(ss).encode()).hexdigest())
ss = {'a', 'b', 'c', 'd', 'e', 'f', 'g'}
print(ss)
print(hashlib.md5(str(ss).encode()).hexdigest())
I see that the resulting set ss
is same within a script run, however, it's different across different script runs.
Output of 1st run:
{'e', 'a', 'd', 'b', 'g', 'f', 'c'}
71ac8e6e505b445790b9f943d67ae8e9
{'e', 'a', 'd', 'b', 'g', 'f', 'c'}
71ac8e6e505b445790b9f943d67ae8e9
Output of 2nd run:
{'b', 'e', 'g', 'd', 'f', 'c', 'a'}
274892f97127704494b6b80face616fd
{'b', 'e', 'g', 'd', 'f', 'c', 'a'}
274892f97127704494b6b80face616fd
I am trying to understand, why the outputs are same within a run, but different across runs?
Thanks!