Skip to content

Instantly share code, notes, and snippets.

@whitews
Created April 4, 2013 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whitews/5310341 to your computer and use it in GitHub Desktop.
Save whitews/5310341 to your computer and use it in GitHub Desktop.
Recursively find children in a dictionary and return them all as a flat list
def find_children(d, i):
l = list()
l.append(d['name'])
d['id'] = i
if 'children' in d:
for child in d['children']:
l.extend(find_children(child, i + len(l)))
return l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment