[Tutor] Faster list searching?

Tim Peters tim.peters at gmail.com
Thu Nov 19 01:03:30 CET 2009


[Luke Paireepinart]
>> 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.

[also Luke Paireepinart]
> Never mind about this, Kent already gave basically the same code sample I
> was going to.

So long as the cat's out of the list, may as well do it "the obvious"
;-) way too:

result = set(list1) - set(list2)

Of course the result is a set then.  Maybe that will work fine in
context, maybe not.  I leave it as an exercise to figure out how to
change it back into a list (hint:  try the obvious way first ;-) ).


More information about the Tutor mailing list