multiple sequences to filter()

Huaiyu Zhu hzhu at localhost.localdomain
Tue Aug 29 20:16:11 EDT 2000


On Thu, 24 Aug 2000 16:18:22 +0000, Peter Schneider-Kamp
<nowonder at nowonder.de> wrote: 
>Ben Wolfson wrote:
>> 
>> list1, list2 = filter(lambda x,y: x==y, list1, list2)
>> 
>> Which, of course, does not work, even though it seems like a natural thing
>> to do.
>
>If you can explain the meaning of that in general terms
>(for l1, l2, ... = filter(boolfunc, l1, l2, ...)
>it shouldn't be a problem to implement.
>
>I doubt that you can come up with one, though.
>

This might be what Ben wanted

>>> list1=[1,2,3,4,5]
>>> list2=[1,3,2,4,5]
>>> apply(map, [None] + filter(lambda x:x[0]==x[1], map(None, list1, list2)))
[(1, 4, 5), (1, 4, 5)]

Huaiyu



More information about the Python-list mailing list