2

I hope this is a easy one.

Is there any possiblity to call itertools.product with a yet (not hardcoded) not knwon number of arguments?

Something like this:

itertools.product(x[0],x[1],x[2],....)

and the dimension of x can't be hardcoded

Thanks!

sklingel
  • 169
  • 2
  • 9

3 Answers3

3

Try:

itertools.product(*x)

i.e. we unpack the argument list.

arshajii
  • 123,543
  • 24
  • 232
  • 276
2

You can use

itertools.product(*x)
Phae7rae
  • 504
  • 2
  • 4
  • 14
1

Lookup *args and **kwargs?

a = [1,2,3]
b = [2,3,4]
c= [a,b]

itertools.product(*c)

You can pass array of arguments using *

Community
  • 1
  • 1
Ranjith Ramachandra
  • 9,779
  • 12
  • 52
  • 89