why are these exec times so different?
r.e.s.
r.s at XXmindspring.com
Wed Dec 17 16:00:32 EST 2003
"r.e.s." <r.s at XXmindspring.com> wrote ...
gads! as soon as I clicked Send, I saw the obvious.
> def f1(s):
> """ do outer & inner loop """
> D = {}
> for i in xrange(len(s)):
> for j in xrange(len(s)-i+1):
> D[s[j:j+i]] = True
> return len(D)
to be comparable to f2, `D={}` needs to be in the
inner loop, otherwise D grows much larger --
it's the growth of D that accounts for the timing
difference I was noticing!
sorry for bothering everyone with my "learning
experience"
More information about the Python-list
mailing list