curious curious - 4 months ago 9
Python Question

How to call a function for every for iteration of a zip of two lists in Python

I have two lists:

a=[1,2,3]
,
b=[a,b,c]


I want for each
zip
of those two to call a function, but not to do it in a trivial way inside a for loop. Is there a pythonic way? I tried with a
map
:

map(func(i,v) for i,v in zip(a,b))


but it does not work

Answer

If the function func doesn't return anything, you could use:

any(func(i, v) for i,v in zip(a, b))

Which will return False but not accumulate the results.