diff --git a/Tree.py b/Tree.py new file mode 100755 index 0000000..1b41ef7 --- /dev/null +++ b/Tree.py @@ -0,0 +1,35 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# \file Tree.py +# \brief TODO +# \author Florent Guiotte +# \version 0.1 +# \date 21 sept. 2017 +# +# TODO details + +import collections + +def Tree(): + return collections.defaultdict(Tree) + +def walk(node): + """iterate tree in pre-order depth""" + if isinstance(node, str): yield "+-" + node + if not isinstance(node, str): + for child in node.values(): + for n in walk(child): + yield "| " + n + +if __name__ == "__main__": + t = Tree() + t[1] = "test" + t[2][1] = "yoyo" + t[2][2] = "qweqweqwe" + t[3][1] = "u wot" + t[2][3][1] = "yoloy" + t[2][3][2][1] = "qwe" + t[4] = "wat" + + for i in walk(t): + print(i)