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!!!

2
  • 1
    Because hash computes a hash based on the object and the tuple(hash_string) is a different object every time (see here). What you need is a hash function like MD5 see here Commented Jun 27, 2022 at 14:19
  • It's supposed to change every time you run your program. See peps.python.org/pep-0456 Commented Jun 28, 2022 at 2:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.