Skip to content

Instantly share code, notes, and snippets.

@jtauber
Created May 16, 2013 17:18
Show Gist options
  • Save jtauber/5593409 to your computer and use it in GitHub Desktop.
Save jtauber/5593409 to your computer and use it in GitHub Desktop.
def struct_hash(structure):
if isinstance(structure, list):
r = "list:" + repr([struct_hash(item) for item in structure])
elif isinstance(structure, dict):
r = "dict:" + repr([(struct_hash(key), struct_hash(value)) for (key, value) in sorted(structure.items())])
elif isinstance(structure, str):
r = "unicode:" + repr(unicode(structure))
elif isinstance(structure, unicode):
r = "unicode:" + repr(structure)
elif isinstance(structure, int):
r = "int:" + repr(structure)
else:
print type(structure)
raise Exception
return sha_constructor(r).hexdigest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment