Skip to content

Instantly share code, notes, and snippets.

@ilovechai
Created May 18, 2021 16:44
Show Gist options
  • Save ilovechai/fc79e2c70b3f8557df82fcfcc858c47b to your computer and use it in GitHub Desktop.
Save ilovechai/fc79e2c70b3f8557df82fcfcc858c47b to your computer and use it in GitHub Desktop.
Python snippet to create frozen sets of nested dictionaries.
def freeze(o):
if isinstance(o, dict):
return frozenset({k: freeze(v) for k, v in o.items()}.items())
if isinstance(o, list):
return frozenset([freeze(v) for v in o])
return o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment