List comprehension equivalent to map on two lists in parallel [duplicate] List comprehension equivalent to map on two lists in parallel [duplicate] python-3.x python-3.x

List comprehension equivalent to map on two lists in parallel [duplicate]


map() with multiple arguments is the equivalent of using the zip() function on those extra arguments. Use zip() in a list comprehension to do the same:

[func(x, y) for x, y in zip(xs, ys)]

Generally speaking, any map(func, a1, a2, .., an) expression can be transformed to a list comprehension with [func(*args) for args in zip(a1, a2, .., an)].