Last active
April 13, 2023 06:40
-
-
Save Mehanik/918b3d42e3bab5778f303075c16a9ac1 to your computer and use it in GitHub Desktop.
Flatten python dict
This file contains 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
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