Created
October 15, 2016 21:01
-
-
Save mehdidc/cd02ab212c37afe59b4cb80ae4db2c11 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import collections | |
def flatten_dict(l): | |
d = {} | |
for k, v in l.items(): | |
if isinstance(v, collections.Mapping): | |
d.update(flatten_dict(v)) | |
elif isinstance(v, list) or isinstance(v, tuple): | |
for i, l in enumerate(v): | |
d[k+'_{}'.format(i)] = l | |
else: | |
d[k] = v | |
return d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment