0

I have 3 lists of different size.

A=[1500,1000,500]
B=[159,179]
C=[6,9,12,18]

I want it to multiply and get 24(AxBxC) lists like

[[1500,159,6],[1000,159,9],[500,159,12],[1500,159,18],.....[500,179,18]]
Ravi Ranjan
  • 107
  • 1
  • 1
  • 11

1 Answers1

1

Seems like you want the cartesian product of the three lists. You can use itertools.product:

from itertools import product
my_lists = [A,B,C]
[i for i in product(*my_lists)]

[(1500, 159, 6),
 (1500, 159, 9),
 (1500, 159, 12),
 (1500, 159, 18),
 (1500, 179, 6),
 (1500, 179, 9),
 (1500, 179, 12),
 (1500, 179, 18),
 (1000, 159, 6),
 (1000, 159, 9),
...
yatu
  • 80,714
  • 11
  • 64
  • 111
  • 1
    Thanks! It was really helpful – Ravi Ranjan Apr 19 '19 at 16:39
  • You're welcome. @RaviRanjan by checking your past questions it seems like you're not accepting answers. Please don't forget to do so if you find them helpful. Check [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) – yatu Apr 19 '19 at 16:45