dict is really slow for big truck

MRAB google at mrabarnett.plus.com
Wed Apr 29 20:34:36 CEST 2009

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()?

If sep is not specified or is None, a different splitting algorithm is 
applied: runs of consecutive whitespace are regarded as a single 
separator, and the result will contain no empty strings at the start or 
end if the string has leading or trailing whitespace. Consequently, 
splitting an empty string or a string consisting of just whitespace with 
a None separator returns [].

More information about the Python-list mailing list