I'm looking to map over a function with lists for specific arguments.
def add(x, y):
return(x + y)
list1 = [1, 2, 3]
list2 = [3, 4, 5]
After some research I have been able to successfully do it using map and a lambda function.
list(map(lambda x, y: add(x, y), list1, list2))
I was wondering, is it better to do this using an iterator? I tried the following but couldn't figure it out:
[add(x, y), for x, y in list1, list2]
or
[add(x, y), for x in list1 for y in list2]
Thanks in advance!
zipfor a list comprehsion