Number of distinct substrings of a string [continuation]
n00m
n00m at narod.ru
Sun Nov 29 04:26:23 EST 2009
This worked out in 5.28s
Imo it's not that *much* slower
(of course, Psyco can't help here)
===================================
import itertools
def subs(s):
return len(set(itertools.chain(
s[i:j]
for i in xrange(len(s))
for j in xrange(i, len(s)+1)))) - 1
from time import time
t = time()
import sys
sys.stdin = open('D:/88.txt', 'rt')
f = sys.stdin.read().split()
sys.stdin.close()
z = open('D:/99.txt', 'wt')
for tc in range(int(f[0])):
s = f[tc + 1]
print >> z, subs(s)
print >> z, time() - t
z.close()
==================================================
More information about the Python-list
mailing list