I want to create a N-ary tree in which each node will contain a key(name) and a value.
1 root then N children with two fields = name and associate value and again each children have N-children with 2 fields.
looking for simpler approach without using class using only dictionary and lists (if possible??).
class Node():
#Do something
# ....
class Node(object):
def __init__(self, name, value):
self.name = name
self.value = value
self.children = []
def add_child(self, obj):
self.children.append(obj)
You say youre looking for a "simpler approach without using class" but my claim here is that 9 times out of 10 using a class for this will be the simpler approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With