Skip to content

Instantly share code, notes, and snippets.

@ZSendokame
Last active March 2, 2024 11:57
Show Gist options
  • Save ZSendokame/7f571dbe12dd75e9e0e72c9e989ec99a to your computer and use it in GitHub Desktop.
Save ZSendokame/7f571dbe12dd75e9e0e72c9e989ec99a to your computer and use it in GitHub Desktop.
flattening of dictionaries.
def flatten(structure: dict, head = [], flattened = {}) -> list:
for key, value in structure.items():
if isinstance(value, dict):
head.append(key)
flatten(value, [*head, key], flattened)
else:
flattened['__'.join(head)] = value
return flattened
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment