curious curious - 1 year ago 52
Python Question

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

I have two lists:


I want for each
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(func(i,v) for i,v in zip(a,b))

but it does not work

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download