Created
April 20, 2012 12:06
-
-
Save ferdef/2428105 to your computer and use it in GitHub Desktop.
Create a flat dictionary from a nested dictionary
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 flat_dict(dictionary, out, pre=''): | |
""" | |
Create a flat dictionary from a nested dictionary | |
out should be an empty dictionary | |
Currently I don't really know what to do with nested dict keys... | |
""" | |
for key, value in dictionary.iteritems(): | |
out[pre + key] = value | |
if isinstance(value, dict): | |
flat_dict(value, out, pre + key + ':') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment