-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.py
More file actions
26 lines (25 loc) · 775 Bytes
/
node.py
File metadata and controls
26 lines (25 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class node:
#edges: list of other nodes max length should be r
#probability: probability of this symbol occuring
#symbol: symbol
def __init__(self, edges, probability, symbol):
self.edges = edges
self.probability = probability
self.symbol = symbol
def to_string(self):
return self.symbol + "("+str(self.probability) +")"
def is_leaf(self):
if len(self.edges) <=0:
return True
else:
return False
def print_tree(base_node, depth):
tabs = get_tabs(depth)
print(tabs, base_node.to_string() )
for sub_node in base_node.edges:
print_tree(sub_node, depth + 1)
def get_tabs(num):
tabs = ""
for i in range(0, num):
tabs = tabs + "\t"
return tabs