Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JokerMartini/44bab71952c9d64614f3 to your computer and use it in GitHub Desktop.
Save JokerMartini/44bab71952c9d64614f3 to your computer and use it in GitHub Desktop.
Python: Returns flat list of objects from recursive function
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