Skip to content

Instantly share code, notes, and snippets.

@smokinggoats
Created May 11, 2017 14:51
Show Gist options
  • Save smokinggoats/7483346b9866aa4cf1b1f9e1c330aa97 to your computer and use it in GitHub Desktop.
Save smokinggoats/7483346b9866aa4cf1b1f9e1c330aa97 to your computer and use it in GitHub Desktop.
OList Test
'''
result:
books
books / nl
books / nl / sf
books / nl / ff
books / il / sf
books / il / ff
'''
class Node(object):
_children = []
_name = ''
def __init__(self, name='', children=[]):
self.name = name
self.children = []
@property
def children(self):
return self._children
@children.setter
def children(self, value):
self._children = value
@property
def name(self):
return self._name
@name.setter
def name(self, value):
self._name = value
a = Node(name='books')
for i in range(10):
b = Node(name='{}'.format(i))
for j in range(0,10,2):
b.children.append(Node(name='{}-{}'.format(i,j)))
a.children.append(b)
def walk(node, parent):
path = '{}/{}'.format(parent,node.name)
yield path
for child in node.children:
for n in walk(child, path):
yield n
for i in walk(a, ''):
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment