An IMHO interesting optimization question...

David Eppstein eppstein at ics.uci.edu
Wed Apr 24 20:45:29 EDT 2002


In article <3cc73c81 at nntp.server.uni-frankfurt.de>,
 Michael 'Mickey' Lauer <mickey at tm.informatik.uni-frankfurt.de> wrote:

> stats = {}
...
> 
> # initialize dictionary, so we don't have to check for key-existance later
> for i in xrange( 1, longWord+1 ):
>     stats[i] = 0

Why are you using a dictionary when you know the indices are a 
predetermined range of integers?  Wouldn't it be better to do

    stats = [0]*(longWord+1)

?

Also, if speed is really a problem, you might think about replacing the 
count() function with inline code.

-- 
David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/



More information about the Python-list mailing list