Skip to content

Instantly share code, notes, and snippets.

@DiTo97
Created September 7, 2023 15:48
Show Gist options
  • Save DiTo97/f7a52f646dd9b5a5d8b3b94be581fa56 to your computer and use it in GitHub Desktop.
Save DiTo97/f7a52f646dd9b5a5d8b3b94be581fa56 to your computer and use it in GitHub Desktop.
A frozen set for nested containers
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