dict is really slow for big truck

J. Cliff Dyer jcd at sdf.lonestar.org
Wed Apr 29 16:27:22 EDT 2009


On Wed, 2009-04-29 at 10:05 -0700, 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()?

Good question.  I can't count the number of times I've used
line.strip().split() in my own code, just because I didn't 1) read the
documentation closely enough, or 2) try the alternative, but lo and
behold, they are the same, at least in the cases I was trying to account
for.

' a b c '.split() == ' a b c '.strip().split() == 'a b c'.split()

Thanks for pointing this out.

Cheers,
Cliff





More information about the Python-list mailing list