Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
from functools import idea solution in Clear category for Tree Walker by veky
from functools import singledispatch
@singledispatch
def count(tree, target): return sum(tree_walker(branch, target) for branch in tree)
@count.register(int)
@count.register(str)
def _(tree, target): return False
@count.register
def _(tree: dict, target): return tree_walker(tree.values(), target)
def tree_walker(tree, target): return tree == target or count(tree, target)
Nov. 30, 2019
Comments: