Thanks to another post of mine, I found out about itertools.product(). What I was wondering how to do is to code it so that I can use as many arrays as parameters as possible, with the number of arrays being defined by user input. for example, If the user inputted 2 arrays, it would find the combinations of those 2 arrays, and if they entered 10 arrays it would find the combinations of the 10 arrays.

I tried this:

z=itertools.product(x for x in array)

but that didnt work. any suggestions or help? thanks in advance

Recommended Answers

All 2 Replies

You can use itertools.product(*array) , also if your want your result in a list, you write list(itertools.product(*array)) .

Using your example list
what do you expect the result to look like?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.