For example, I have following two lists
listA=['one', 'two' , 'three']
listB=['apple','cherry','watermelon']
How can I pair those two lists to get this output, using map and lambda?
one apple
two cherry
three watermelon
I know how to do it by the list comprehension,
[print(listA[i], listB[i]) for i in range(len(listA))]
but I can't figure out a map and lambda solution. Any ideas?
解决方案
Here what I got based on what you need (map and lambda),
Input:
listA=['one', 'two' , 'three']
listB=['apple','cherry','watermelon']
list(map(lambda x, y: x+ ' ' +y, listA, listB))
Output:
['one apple', 'two cherry', 'three watermelon']