75 lines
1.4 KiB
Python
Executable File
75 lines
1.4 KiB
Python
Executable File
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
# \file Tree.py
|
|
# \brief TODO
|
|
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
|
# \version 0.1
|
|
# \date 21 sept. 2017
|
|
#
|
|
# TODO details
|
|
|
|
import collections
|
|
import cv2
|
|
import ipdb
|
|
|
|
#class Node:
|
|
# def __init__(self, val):
|
|
# self.value = val
|
|
#
|
|
#class Tree:
|
|
# def __init__(self):
|
|
# self.root = collections.defaultdict(Tree)
|
|
|
|
def Tree():
|
|
return collections.defaultdict(Tree)
|
|
|
|
def walk(node):
|
|
"""iterate tree in pre-order depth"""
|
|
if not isinstance(node, collections.defaultdict): yield "+-{}".format(node)
|
|
if isinstance(node, collections.defaultdict):
|
|
for child in node.values():
|
|
for n in walk(child):
|
|
yield "| " + n
|
|
|
|
def helloworld():
|
|
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"
|
|
|
|
x = Tree()
|
|
t[5] = x
|
|
for i in range(25):
|
|
y = Tree()
|
|
for j in range(10):
|
|
x[j] = "quto"
|
|
y['parent'] = x
|
|
x['a'] = y
|
|
x = y
|
|
|
|
for i in walk(t):
|
|
print(i)
|
|
|
|
def maxtree():
|
|
img = cv2.imread('img/lena.ppm', 0)
|
|
print(img)
|
|
root = Tree()
|
|
index = 0
|
|
for i in img:
|
|
for j in i:
|
|
root[index] = j
|
|
index += 1
|
|
|
|
for i in walk(root):
|
|
print(i)
|
|
|
|
print(root)
|
|
|
|
if __name__ == "__main__":
|
|
helloworld()
|
|
#maxtree()
|