[Tutor] Faster list searching?

Luke Paireepinart rabidpoobear at gmail.com
Thu Nov 19 00:54:13 CET 2009


On Wed, Nov 18, 2009 at 5:03 PM, Bill Campbell <bill at celestial.net> wrote:

>
> When I have had to deal with large lists, I have found that using
> an intermediate dictionary can save huge amounts of time.
> Something like:
>
> dict2 = {}.fromkeys(list2)
> for x in list1:
>        if x not in dist2:
>                dict2[x] = True
>
> list2 = dict2.keys()
>
> This is really just a round-about way of using sets.
I don't really want to give a code-sample unless he's confirmed he's not
doing this as homework, but the set version is much more simple (shorter
code that makes more sense) and extremely quick as well.  If you're
interested in it, Bill, reply to me off-list and I'll send it to you.

-Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091118/224b227d/attachment.htm>


More information about the Tutor mailing list