Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Tree Walker by U.V
def tree_walker(tree, target):
if tree == target:
return 1
if isinstance(tree,(list, tuple)):
return sum(tree_walker(subtree, target) for subtree in tree)
if isinstance(tree, dict):
return sum(tree_walker(subtree, target) for subtree in tree.values())
return 0
Jan. 21, 2023
Comments: