Most efficient solution?
Alexandre Fayolle
alf at leo.logilab.fr
Mon Jul 16 10:59:27 EDT 2001
On 16 Jul 2001 16:39:34 +0200, Bernhard Herzog <bh at intevation.de> wrote:
>A bit more elegant, perhaps, and a little faster still would be to use 1
>as the value in C and directly use C.get in filter:
>
>C = {}
>for item in B:
> C[item] = 1
>
>A = filter(C.get, A)
Much more elegant, of course.
This is a good example of iterative refactoring ;o)
I suppose that the first loop could also be rewritten using map, in order
to squeeze some more juice out of the beast:
C={}
map(lambda item,dic = C: dic[item]=1, B)
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