Most efficient solution?

Christopher A. Craig com-nospam at ccraig.org
Tue Jul 17 08:21:50 EDT 2001


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bernhard Herzog <bh at intevation.de> writes:

> 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)

The main gain of this is just the elimination of the (costly) lambda
function.  You could also do this with

C={}
for i in B: C[i]=None
A = filter(C.has_key, A)

which would operate in exactly the same manner, but which I find less
confusing.


- -- 
Christopher A. Craig <com-nospam at ccraig.org>
"If more of us valued food and cheer and song above hoarded gold, it would
be a merrier world." - J.R.R. Tolkien
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Processed by Mailcrypt

iEYEARECAAYFAjtULd4ACgkQjVztv3T8pzsHyACdGRROZ735+4ruUZelWzToYnkO
XfEAoJuotBNV6WzBjuf6lPguZhtY3dq/
=ugcI
-----END PGP SIGNATURE-----



More information about the Python-list mailing list