Created
December 3, 2015 13:22
-
-
Save JokerMartini/44bab71952c9d64614f3 to your computer and use it in GitHub Desktop.
Python: Returns flat list of objects from recursive function
This file contains hidden or 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 get_nodes(items=[], ages=[]): | |
myresults = [] | |
print "Searching..." | |
# pseudo code | |
for item in items: | |
if item.age in ages: | |
print "\t","valid age" | |
myresults.append(item) | |
myresults.extend( get_nodes(items=item.children, ages=ages) ) | |
return myresults |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment