0

I have a python file script that I want to run many times. but any time I run it the return value is different but the input is the same:

below code show it:

from typing import Iterable
def get_hash(hash_string: Iterable[str]) -> str:
    hash_string.sort()
    return str(hash(tuple(hash_string)))

sample_list = ['00b3ee037a1cfba5158e7c9fad04ced03b92fe3b', '02db69a00d40834ab095cbbbe18fe8945229df9b']
get_hash(sample_list)

Any time I run this script the result is different!!!

Alex
  • 31
  • 4
  • 1
    Because `hash` computes a hash based on the object and the `tuple(hash_string)` is a different object every time (see [here](https://docs.python.org/3/library/functions.html#hash)). What you need is a hash function like MD5 see [here](https://stackoverflow.com/questions/5297448/how-to-get-md5-sum-of-a-string-using-python) – Sajad Jun 27 '22 at 14:19
  • It's supposed to change every time you run your program. See https://peps.python.org/pep-0456/ – President James K. Polk Jun 28 '22 at 02:24

0 Answers0