Created
September 7, 2023 15:48
-
-
Save DiTo97/f7a52f646dd9b5a5d8b3b94be581fa56 to your computer and use it in GitHub Desktop.
A frozen set for nested containers
This file contains hidden or 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
from typing import Any | |
# TODO: type hinting | |
def deepfrozenset(obj: Any) -> Any: | |
if isinstance(obj, dict): | |
return frozenset([(key, deepfrozenset(val)) for key, val in obj.items()]) | |
if isinstance(obj, list): | |
return frozenset([deepfrozenset(val) for val in obj]) | |
return obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment