how do I multiply lists together in python using a function? This is what I have:
list = [1, 2, 3, 4] def list_multiplication(list, value):
If you have two lists A and B of the same length, easiest is to zip them:
A
B
zip
>>> A = [1, 2, 3, 4] >>> B = [5, 6, 7, 8] >>> [a*b for a, b in zip(A, B)] [5, 12, 21, 32]
Take a look at zip on its own to understand how that works:
>>> zip(A, B) [(1, 5), (2, 6), (3, 7), (4, 8)]