Skip to content

Instantly share code, notes, and snippets.

@kadirmalak
Last active December 9, 2018 18:08
Show Gist options
  • Save kadirmalak/5945569f43bf1a954ac72d068e21a15b to your computer and use it in GitHub Desktop.
Save kadirmalak/5945569f43bf1a954ac72d068e21a15b to your computer and use it in GitHub Desktop.
def ifor(*lists):
root = Node('ROOT')
for L in lists:
leaves = list(root.leaves())
for data in L:
# create once, use multiple times
# this way we end up with a graph, instead of a tree
new_node = Node(data)
for leaf in leaves:
# leaves() function may return same nodes multiple times
if not new_node in leaf.children:
leaf.add(new_node)
return root.routes_to_leaves()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment