Skip to content
Permalink
6d5cc671f5
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
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)