Skip to content
Advertisement

Python itertools.product with variable number of arguments

I am trying to write a module to combine a variable number of lists using itertools.product.

The closest I can get is:

JavaScript

This doesn’t work, because lists is a single list, so it just returns the original sequence. But I can’t figure out how to pass each element of the lists variable to itertools.

Thanks for any suggestions.

Advertisement

Answer

You need to use * to separate the single list into its constituent lists:

JavaScript

See the Python Tutorial section on Unpacking Argument Lists.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement