Last active
December 22, 2015 16:03
-
-
Save mondwan/2a8c90d93d3a4dee27f7 to your computer and use it in GitHub Desktop.
How to do bfs in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from treelib import Tree | |
tree = Tree() | |
# Create a tree for demo purpose | |
tree.create_node('A', 'a') | |
tree.create_node('B', 'b', parent='a') | |
tree.create_node('C', 'c', parent='a') | |
tree.create_node('D', 'd', parent='b') | |
tree.create_node('E', 'e', parent='b') | |
tree.create_node('F', 'f', parent='c') | |
tree.create_node('G', 'g', parent='c') | |
tree.create_node('H', 'h', parent='e') | |
# BFS | |
for n in tree.expand_tree('a', Tree.WIDTH): | |
print(tree[n].tag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment