Most efficient solution?

Alexandre Fayolle alf at leo.logilab.fr
Mon Jul 16 11:44:13 EDT 2001


On 16 Jul 2001 17:39:47 +0200, Bernhard Herzog <bh at intevation.de> wrote:
>Alex <new_name at mit.edu> writes:
>
>> > C = {}
>> > for item in B:
>> >     C[item] = 1
>> > 
>> > A = filter(C.get, A)
>
>I just realized that it does exactly the opposite of what the OP wanted.
>It keeps all occurences of words in B instead of removing them. :(

Gosh, you're right. :o)
Well, we'll get to use lambda, in the end.

A = filter(lambda item, dic = C: not dic.get(item), A)

should do the trick. 

Alexandre Fayolle
-- 
LOGILAB, Paris (France).
http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org
Narval, the first software agent available as free software (GPL).



More information about the Python-list mailing list