How to Hash a Dictionary Object in Python?

The following code is an example of hashing a dictionary object in Python:


import hashlib
import json

item = {"name":"abc", "email":"[email protected]", "id":"22"}
result = hashlib.md5(json.dumps(item, sort_keys=True).encode('utf-8'))
hash_value = result.hexdigest()

print("Dictionary hash value = ", hash_value)
Output:
Dictionary hash value = 301231800c907fb2eabbc5c5d7f48a41