Created
May 18, 2021 16:44
-
-
Save ilovechai/fc79e2c70b3f8557df82fcfcc858c47b to your computer and use it in GitHub Desktop.
Python snippet to create frozen sets of nested dictionaries.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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