Skip to content

Instantly share code, notes, and snippets.

@ferdef
Created April 20, 2012 11:39
Show Gist options
  • Save ferdef/2427956 to your computer and use it in GitHub Desktop.
Save ferdef/2427956 to your computer and use it in GitHub Desktop.
Flatten keys from a nested dictionary
def flat_keys(dictionary, out):
"""
Flatten keys from a nested dictionary
out should be an empty list
"""
for key in dictionary.keys():
out.append(key)
if isinstance(dictionary[key], dict):
flat_keys(dictionary[key], out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment