Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def make_hash(o):
- """
- Makes a hash from a dictionary, list, tuple or set to any level, that contains
- only other hashable types (including any lists, tuples, sets, and dictionaries).
- """
- if isinstance(o, (set, tuple, list)):
- return tuple([make_hash(e) for e in o])
- elif not isinstance(o, dict):
- return hash(o)
- new_o = deepcopy(o)
- for k, v in new_o.items():
- new_o[k] = make_hash(v)
- return hash(tuple(frozenset(sorted(new_o.items()))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement