An IMHO interesting optimization question...

Scott David Daniels Scott.Daniels at Acm.Org
Fri Apr 26 04:23:38 EDT 2002


The best I found (I read from a file to try several strategies 
per run) did reasonably well as "python -OO race.py"
..
longWord=15
filename = 'folio.txt'

def lcounts( words ):
   "Increments the wordcounter -- locals and seq arg"
   lstats = stats
   for word in words:
       length = len( word )
       if length > longWord:
           length = longWord
       lstats[length] += 1

def laruns():
    global stats
    stats = [0] * (longWord+1)
    start = time.time()
    findall = wordExp.findall
    for line in file(filename):
        lcounts( findall( line ))
    return time.time() - start
..

-Scott.Daniels at Acm.Org






More information about the Python-list mailing list