Tree Walking

Additional example

Comments are moderated. It may take a few minutes before your comment appears.
Markdown is supported in your comments.

def children(token, tree):
    "returns a list of every child"
    visited = set()
    to_crawl = deque([token])
    while to_crawl:
        current = to_crawl.popleft()
        if current in visited:
            continue
        visited.add(current)
        node_children = set(tree[current])
        to_crawl.extend(node_children - visited)
    return list(visited)
Name:
Mail: (not shown)

Please type this: