0

I have a list looks like below

[['a'], ['b'], [[1], [2], [3]], ['d']]

and I need to get

[['a'], ['b'], [1], ['d']], [['a'], ['b'], [2], ['d']], [['a'], ['b'], [3], ['d']]

I saw few posts and found itertools.product, but I think this needs multiple lists in same dimension as argument.

Is there any way to get the result?

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
Dalek Sec
  • 83
  • 1
  • 11

1 Answers1

0

You can use itertools.product with the star operator (see here).

That would look like

from itertools import product
A = [['a'], ['b'], [[1], [2], [3]], ['d']]

for a in product(*A):
   print(a)

# yields
# ('a', 'b', [1], 'd')
# ('a', 'b', [2], 'd')
# ('a', 'b', [3], 'd')
syltruong
  • 2,563
  • 20
  • 33