For example:
X = [1, 3]
Y = [-1, 1, 0]
The output should be like this:
[-1, 1, 0, -3, 3, 0]
Is there a way to do this and also for other calculations such as summation. I searched over here and internet but I could not find any solution.
For example:
X = [1, 3]
Y = [-1, 1, 0]
The output should be like this:
[-1, 1, 0, -3, 3, 0]
Is there a way to do this and also for other calculations such as summation. I searched over here and internet but I could not find any solution.
i think that's what you need.
X = [1,3]
Y = [-1,1,0]
res = [x*y for x in X for y in Y]
print(res)
As an alternative to list comprehension solution that mentioned by others, product in itertools module, does the same iteration pattern as two nested loops in case you need to work with other iterators in chain or performance matters for large amount of data :
from itertools import product
X = [1, 3]
Y = [-1, 1, 0]
res = [i * j for i, j in product(X, Y)]
print(res)