[Tutor] Quick question regarding Parsing a Delimited string

Garry Bettle garry.bettle at gmail.com
Wed Jul 8 21:43:38 CEST 2009


On Wed, Jul 8, 2009 at 21:37, Kent Johnson<kent37 at tds.net> wrote:
> On Wed, Jul 8, 2009 at 1:22 PM, Rich Lovely<roadierich at googlemail.com> wrote:
>
>> If you really want to speed up the search, you could turn the list of lists
>> into a dict, using the first value in each sublist as a key:
>>
>> dct = dict((i[0], i[1:]) for i in lst)
>>
>> Then you can access it using the normal dictionary interface.
>> dct["3991404"][3]
>
> I'm suspicious of this claim if there is only one lookup needed. You
> iterate the whole list and incur the overhead of constructing a dict.
> If there will be multiple lookups it may well be a win but as always
> there is no substitute for measurement if you want to know what is
> faster.
>
> Kent
>

Hi Kent,

No, I think the dict will be fine:  I have to find every one that is
in my original list.

Many thanks to both you and Rich for all the help.  I'll let you know
how I get on.

Cheers,

Garry


More information about the Tutor mailing list