Created
August 28, 2013 06:47
-
-
Save monicatoth/6362836 to your computer and use it in GitHub Desktop.
Just a small exercise I wrote for myself a while ago. Plenty of room for improvement!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
else: | |
pass | |
def readsimpled(simpled): | |
nodenames = simpled.keys() | |
traceback = [] | |
progression = [] | |
print "Node names:", nodenames | |
for x in nodenames: | |
y = simpled[x] | |
z = [x, y[0]] | |
traceback.append(z) | |
print "Trace back:", traceback | |
for item in traceback: | |
if item[1] == '0': | |
startNode = item[0] | |
progression.insert(0, startNode) | |
else: | |
pass | |
print "Start node:", startNode | |
while len(nodenames) > len(progression): | |
x = traceback.pop() | |
if x[1] == progression[-1]: | |
progression.append(x[0]) | |
print "found progression:", x[1], "-->", x[0] | |
else: | |
traceback.insert(0,x) | |
print "Progression:", progression | |
readout = [] | |
for elem in progression: | |
temp = simpled[elem] | |
readout.append(temp[1]) | |
print "Readout:" | |
for i in readout: | |
print i | |
def readdouble(nodes): | |
predecessor = '0' | |
successor = 'whatever' | |
while successor != '0': | |
for item in nodes: | |
if item[1] == predecessor: | |
print item[0], item[-1] | |
predecessor = item[0] | |
successor = item[2] | |
else: | |
pass | |
if __name__ == "__main__": | |
readsimpled(simpled) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment