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):
You can use a list comprehension:
>>> t = [1, 2, 3, 4] >>> [i**2 for i in t] [1, 4, 9, 16]
Note that 1*1, 2*2, etc is the same as squaring the number.
1*1, 2*2, etc
If you need to multiply two lists, consider zip():
>>> L1 = [1, 2, 3, 4] >>> L2 = [1, 2, 3, 4] >>> [i*j for i, j in zip(L1, L2)] [1, 4, 9, 16]