optimization pointers?
Mel Wilson
mwilson at the-wire.com
Fri Dec 12 11:52:01 EST 2003
In article <3fd9cdf1$0$6970$7a628cd7 at news.club-internet.fr>,
"Anthony McDonald" <tonym1972(at)club-internet(in)fr> wrote:
>Heres my contribution, removing the string append in favour of slices. Buys
>a little speed thanks to xrange.
>
>def lz_comp_mine(text):
> voc = {}
> st = 0
> for cur in xrange(1,len(text)+1):
> if not voc.get(text[st:cur], False):
> voc[text[st:cur]] = True
> st = cur
> return len(voc)
Nice touch! I tried slices and took a huge performance
hit (almost 3x the list version) but I didn't use `for ... in
xrange ...`. It must have all been in the while-loop test
and index incrementing.
Regards. Mel.
More information about the Python-list
mailing list