Last active
July 5, 2020 09:49
-
-
Save tamsanh/0d78ade303dd86f39c67dfa1df9f32c7 to your computer and use it in GitHub Desktop.
Consistent Dictionary Hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import json | |
from typing import Dict, Any | |
def hash_dict(data: Dict[str, Any]): | |
data_str = json.dumps(data, sort_keys=True, default=str) | |
md5 = hashlib.md5() | |
md5.update(data_str.encode("utf-8")) | |
hash_value = md5.hexdigest() | |
return hash_value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment