For example, suppose list_1 = [a,b,c]
and list_2 = [m,n,o]
. I want to compare each item from one list to the other, for example, create an output list such that
[a == m, a == n, a == o, b == m, b == n, b == o...]
For simplicity I'm using the ==
operation but this could also be a summation, e.g.
[a + m, a + n, a + o, b + m...]
I know how I could do this with two loops, but I'm wondering a lambda function with map()
or list comprehensions could be used? I've searched online but only found one-to-one comparisons of list items, e.g. map(lambda x,y: x + y, list_1, list_2)
.