Skip to content

Instantly share code, notes, and snippets.

@boblannon
Created December 21, 2015 17:33
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 boblannon/cf3d14fee1e592c41b66 to your computer and use it in GitHub Desktop.
Save boblannon/cf3d14fee1e592c41b66 to your computer and use it in GitHub Desktop.
def omnihash(obj):
""" recursively hash unhashable objects """
if isinstance(obj, set):
return hash(frozenset(omnihash(e) for e in obj))
elif isinstance(obj, (tuple, list)):
return hash(tuple(omnihash(e) for e in obj))
elif isinstance(obj, dict):
return hash(frozenset((k, omnihash(v)) for k, v in obj.items()))
else:
return hash(obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment