dict is really slow for big truck

MRAB google at mrabarnett.plus.com
Wed Apr 29 16:54:25 EDT 2009


Scott David Daniels wrote:
> MRAB wrote:
>> Scott David Daniels wrote:
>>> Bruno Desthuilliers wrote:
>>>> d = {}
>>>> for line in open(thefile):
>>>>    arr = line.strip().split()
>>>>    d[arr[0]] = arr
>>>
>>> Sorry, not picking on Bruno in particular, but I keep seeing
>>> this formulation around various places.
>>> When does line.strip().split() ever differ from line.split()?
>> ... <explanation of what split does>
> 
> You misunderstand the question.  For what values of line is
> the following expression False?
> 
>     line.strip().split() == line.split()
> 
> If you know of one, I'd like to hear of it.  If not, I assert
> that (baring some incredibly over-ambitous optimizer operations)
>     line.strip().split()
> is simply an inefficient (both performance and text) way of saying:
>     line.split()
> 
 From the explanation it's clear that the .strip() is unnecessary.



More information about the Python-list mailing list