Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
32 lines (26 sloc) 766 Bytes
from collections import defaultdict
trie=defaultdict(list)
labels={}
Node=0
Next=1
data=[]
with open("rosalind_trie.txt","rU") as f:
for line in f:
data.append(line.strip())
for x in data:
Node=0
for y in x:
s=[labels[i] for i in trie[Node]]
if y in s:
Node=trie[Node][s.index(y)]
else:
trie[Node].append(Next)
labels[Next]=y
Node,Next=Next,Next+1
def adjacency(trie,labels,node,f):
for i in trie[node]:
f.write( str(node+1)+' '+str(i+1)+' '+str(labels[i])+'\n')
for n in trie[node]:
adjacency(trie,labels,n,f)
with open("trie_out.txt","w") as f:
adjacency(trie,labels,0,f)
You can’t perform that action at this time.