dict is really slow for big truck

Sion Arrowsmith sion at viridian.paintbox
Wed Apr 29 07:17:23 EDT 2009


 <bearophileHUGS at lycos.com> wrote:
>On Apr 28, 2:54 pm, forrest yang <Gforrest.y... at gmail.com> 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 that's going to make much difference.

You can still get the original result with a single split call
(which may indeed be a significant overhead):

for line in open(file)
   arr=line.strip().split('\t')
   dict[arr[0]]=arr

unless I've misunderstood the data format. (And if I have, is it
really the intention that "1 1\t1\t1" gets overwritten by a
subsequent "1 2\t3\t4" as the original code does?)

-- 
\S

   under construction




More information about the Python-list mailing list