0

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:

array=[['a','b'],['b','c'],['c','a']]
z=itertools.product(x for x in array)

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

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by vegaseat
1

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

0

Using your example list
array=[['a','b'],['b','c'],['c','a']]
what do you expect the result to look like?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.