filter with dynamic value
Achim Domma
achim.domma at syynx.de
Fri Sep 14 08:58:02 EDT 2001
Hi,
I have something like this:
ids = [(1,'abc'),(2,'abc'),(3,'xyz'),(4,'xyz')]
comp = 'xyz'
now I want to use filter to remove all items from ids which don't have 'xyz'
as second value. I think the following should work:
filter(lambda x: x[1]=='xyz')
but how can I do this with an dynamic value ? If I try the following I get
problems with the scope of comp :
filter(lamdba x: x[1]==comp)
I think this can't be to complicated, but it seems that my C++ trained brain
hides once again the solution from me ...
greetings
Achim
More information about the Python-list
mailing list