Skip to content

Instantly share code, notes, and snippets.

@tamsanh
Last active July 5, 2020 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamsanh/0d78ade303dd86f39c67dfa1df9f32c7 to your computer and use it in GitHub Desktop.
Save tamsanh/0d78ade303dd86f39c67dfa1df9f32c7 to your computer and use it in GitHub Desktop.
Consistent Dictionary Hash
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