Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. def make_hash(o):
  2.     """
  3.    Makes a hash from a dictionary, list, tuple or set to any level, that contains
  4.    only other hashable types (including any lists, tuples, sets, and dictionaries).
  5.    """
  6.  
  7.     if isinstance(o, (set, tuple, list)):
  8.         return tuple([make_hash(e) for e in o])    
  9.     elif not isinstance(o, dict):
  10.         return hash(o)
  11.  
  12.     new_o = deepcopy(o)
  13.     for k, v in new_o.items():
  14.         new_o[k] = make_hash(v)
  15.  
  16.     return hash(tuple(frozenset(sorted(new_o.items()))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement