Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
9-liner: Function recursion for the leaves of fall solution in Clear category for Tree Walker by Stensen
def tree_walker(tree, target):
answer = 0
if isinstance(tree, (int, str, type(target))):
if tree == target: answer += 1
if isinstance(tree, (list, tuple)):
for i in tree: answer += tree_walker(i, target)
if isinstance(tree, dict):
for i in tree.values(): answer += tree_walker(i, target)
return answer
Oct. 11, 2020