Skip to content

Instantly share code, notes, and snippets.

@monicatoth
monicatoth / alphabet_tree.py
Created September 6, 2013 06:27
Creates a complete (a.k.a. "perfect") binary tree from a given array.
# Sample array
alpha = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O']
# Note from Alan:
# the array will always be the right length to produce
# a balanced tree where every node has two children.
# Decided on a list representation
# The end result will look like: [['A', ['B', 'I']], ['B', ['C', 'F']] . . . ]
final_tree = []
@monicatoth
monicatoth / node_reader
Created August 28, 2013 06:47
Just a small exercise I wrote for myself a while ago. Plenty of room for improvement!
simple = [['a','b','once'], ['b','c','upon'], ['c','d','a time']]
double = [['a','0','b','once again'], ['b','a','c','upon'], ['c','b','0','a time']]
simpled = {'a':['0','once'], 'b':['a', 'upon'], 'c':['b', 'a dictionary']}
def readsimple(start, nodes):
for item in nodes:
x = item[1]
if item[0] == start:
print item[0], item[-1]
readsimple(x, nodes)