Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (39 sloc) 997 Bytes
from collections import defaultdict
from sys import setrecursionlimit
setrecursionlimit(1500)
trie=defaultdict(list)
labels={}
Node=0
Next=1
data=[]
with open("rosalind_suff.txt","rU") as f:
line=f.readline().strip()
for i in range(len(line)):
data.append(line[i:])
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
f=open("suff_out.txt","w")
def strings(trie,node,s):
#print node,s
if len(trie[node])>1:
f.write(s+labels[node]+'\n')
for n in trie[node]:
strings(trie,n,'')
return
if len(trie[node])==1:
strings(trie,trie[node][0],s+labels[node])
return
if len(trie[node])==0:
f.write(s+'$\n')
return
for x in trie[0]:
strings(trie,x,'')
f.close()
You can’t perform that action at this time.