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() ================================================== -- http://mail.python.org/mailman/listinfo/python-list