I have two lists:
list1 = [1,2,3] list2 = [4,5,6]
I want to multiply each number in the first list with each number in the second list to get the result:
list3 = [4,5,6,8,10,12,12,15,18]
How do I do this?
I have two lists:
list1 = [1,2,3] list2 = [4,5,6]
I want to multiply each number in the first list with each number in the second list to get the result:
list3 = [4,5,6,8,10,12,12,15,18]
How do I do this?
There could be a more pythonic way to do this but this gets the job done.
lst1 = [1,2,3]
lst2 = [4,5,6]
lst3 = []
for i in lst1:
for j in lst2:
lst3.append(i*j)
print(lst3)
Using list comprehension:
print([(l1*l2) for l1 in lst1 for l2 in lst2])