Skip to content

Instantly share code, notes, and snippets.

@Mehanik
Last active April 13, 2023 06:40
Show Gist options
  • Save Mehanik/918b3d42e3bab5778f303075c16a9ac1 to your computer and use it in GitHub Desktop.
Save Mehanik/918b3d42e3bab5778f303075c16a9ac1 to your computer and use it in GitHub Desktop.
Flatten python dict
def flatten_dict(data, sep="."):
r = {}
for k, v in data.items():
if not isinstance(v, dict):
r[k] = v
continue
for kk, vv in flatten_dict(v, sep).items():
r[f"{k}{sep}{kk}"] = vv
return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment