filter with dynamic value
achim.domma at syynx.de
Fri Sep 14 14:58:02 CEST 2001
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=='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==comp)
I think this can't be to complicated, but it seems that my C++ trained brain
hides once again the solution from me ...
More information about the Python-list