Let’s say I have a list of tuples:
a = [(1, 2), (3, 4), (4, 5)]
and another list, no tuples:
b = [1, 2, 3]
How would I use list comprehension to multiply only the first value of each tuple in a by each respective value in b? That is, [a[0][0] * b[0], a[1][0] * b[1], a[2][0] * b[2]]
(Should equal [1, 6, 12])
The
zipfunction is the key.