Created
April 4, 2013 13:29
-
-
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
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 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