Last active
May 9, 2017 07:37
-
-
Save BibMartin/4fca400c9916f541fbfcc4045cfd5125 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
| def unstack(x, prefix=""): | |
| if isinstance(x, dict): | |
| out = {} | |
| for key, val in x.items(): | |
| z = unstack(val, prefix=key+'.') | |
| if isinstance(z, dict): | |
| for subkey, subval in z.items(): | |
| out[prefix+subkey] = subval | |
| else: | |
| out[prefix+key] = val | |
| return out | |
| elif isinstance(x, list): | |
| return unstack({str(i): val for i,val in enumerate(x)}, prefix=prefix) | |
| else: | |
| return x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment