Skip to content

Instantly share code, notes, and snippets.

@ferdef
Created April 20, 2012 12:06
Show Gist options
  • Save ferdef/2428105 to your computer and use it in GitHub Desktop.
Save ferdef/2428105 to your computer and use it in GitHub Desktop.
Create a flat dictionary from a nested dictionary
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