Skip to content

Instantly share code, notes, and snippets.

@lucasbracher
Created November 7, 2025 17:13
Show Gist options
  • Save lucasbracher/41154b9027e53abc9104ff949cd9bc80 to your computer and use it in GitHub Desktop.
Save lucasbracher/41154b9027e53abc9104ff949cd9bc80 to your computer and use it in GitHub Desktop.
empty_dict.py
# Get a dictionary and empty it, leaving just the structure:
def empty_dict(d):
if isinstance(d, dict):
return {k: empty_dict(v) for k, v in d.items()}
elif isinstance(d, list):
return [empty_dict(d[0])] if d else []
else:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment