<[email protected]> wrote:
>On Apr 28, 2:54 pm, forrest yang <[email protected]> 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
--
http://mail.python.org/mailman/listinfo/python-list