Re: dict is really slow for big truck

2009-05-01 Thread Thomas G. Willis
On Apr 28, 8:54 am, forrest yang wrote: > i try to load a big file into a dict, which is about 9,000,000 lines, > something like > 1 2 3 4 > 2 2 3 4 > 3 4 5 6 > > code > for line in open(file) >    arr=line.strip().split('\t') >    dict[arr[0]]=arr > > but, the dict is really slow as i load more d

Re: dict is really slow for big truck

2009-04-30 Thread Bruno Desthuilliers
forrest yang a écrit : i try to load a big file into a dict, which is about 9,000,000 lines, something like 1 2 3 4 2 2 3 4 3 4 5 6 How "like" is it ?-) code for line in open(file) arr=line.strip().split('\t') dict[arr[0]]=arr but, the dict is really slow as i load more data into the m

Re: dict is really slow for big truck

2009-04-30 Thread Bruno Desthuilliers
bearophileh...@lycos.com a écrit : Sion Arrowsmith: The keys aren't integers, though, they're strings. You are right, sorry. I need to add an int() there. Which is not garanteed to speed up the code FWIW -- http://mail.python.org/mailman/listinfo/python-list

Re: dict is really slow for big truck

2009-04-29 Thread bearophileHUGS
Sion Arrowsmith: > The keys aren't integers, though, they're strings. You are right, sorry. I need to add an int() there. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: dict is really slow for big truck

2009-04-29 Thread Scott David Daniels
prueba...@latinmail.com wrote: It is probably out of habit of using the generalized idiom: line="a,b,c\n" line.strip().split(",") Ah, thank you. I just couldn't figure out where it started. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list

Re: dict is really slow for big truck

2009-04-29 Thread pruebauno
On Apr 29, 1:05 pm, 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

Re: dict is really slow for big truck

2009-04-29 Thread MRAB
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.

Re: dict is really slow for big truck

2009-04-29 Thread J. Cliff Dyer
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. >

Re: dict is really slow for big truck

2009-04-29 Thread Scott David Daniels
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

Re: dict is really slow for big truck

2009-04-29 Thread MRAB
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.spl

Re: dict is really slow for big truck

2009-04-29 Thread Scott David Daniels
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()? --Scott David Daniels

Re: dict is really slow for big truck

2009-04-29 Thread Bruno Desthuilliers
bearophileh...@lycos.com a écrit : On Apr 28, 2:54 pm, forrest yang wrote: i try to load a big file into a dict, which is about 9,000,000 lines, something like 1 2 3 4 2 2 3 4 3 4 5 6 code for line in open(file) arr=line.strip().split('\t') dict[line.split(None, 1)[0]]=arr but, the dict

Re: dict is really slow for big truck

2009-04-29 Thread Sion Arrowsmith
wrote: >On Apr 28, 2:54 pm, forrest yang wrote: >> for line in open(file) >>    arr=line.strip().split('\t') >>    dict[line.split(None, 1)[0]]=arr > >Keys are integers, so they are very efficiently managed by the dict. The keys aren't integers, though, they're strings. Though I don't think tha

Re: dict is really slow for big truck

2009-04-28 Thread Steven D'Aprano
On Tue, 28 Apr 2009 10:25:05 -0700, Aahz wrote: >>but, the dict is really slow as i load more data into the memory, by the >>way the mac i use have 16G memory. is this cased by the low performace >>for dict to extend memory or something other reason. > > Try gc.disable() before the loop and gc.en

Re: dict is really slow for big truck

2009-04-28 Thread bearophileHUGS
On Apr 28, 2:54 pm, forrest yang wrote: > i try to load a big file into a dict, which is about 9,000,000 lines, > something like > 1 2 3 4 > 2 2 3 4 > 3 4 5 6 > > code > for line in open(file) >    arr=line.strip().split('\t') >    dict[line.split(None, 1)[0]]=arr > > but, the dict is really slow

Re: dict is really slow for big truck

2009-04-28 Thread Aahz
In article <7f01f7b7-a561-483a-8e6d-861a8c05f...@p6g2000pre.googlegroups.com>, forrest yang wrote: > >i try to load a big file into a dict, which is about 9,000,000 lines, >something like >1 2 3 4 >2 2 3 4 >3 4 5 6 > >code >for line in open(file) > arr=line.strip().split('\t') > dict[arr[0]]=