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

Recommended Answers

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

Jump to Post

All 2 Replies

Re: Array of Arrays for itertools.product? 80 80

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

Re: Array of Arrays for itertools.product? 80 80

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

Be a part of the DaniWeb community

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