Which would be the most elegant and Pythonic way to permute elements of 5 or 6 lists?
I have a bunch of list like following, where each element will trigger an AJAX call. And when elements from list 3 will be iterated, they might pull out another list which I need to permute as well and I need to get all permutations possible.
List comprehensions are out of discussion because I need to make some operations between each call.
I know about itertools.permutations
but I'm looking for something that will give me more control at each step.
list1 =['e1', 'e2', 'e3']
list2 = ['e1', 'e2', ... , 'e13']
list3 = [up to 15 elements]
variable_list = ['e1', 'e2']
list4 = ['e1', 'e2']
list5 = ['e1', 'e2', ... , 'e16']
Here it's the list I'm trying to deal:
values = [[{'0': '25'},
{'0': '50'},
{'0': '75'},
{'0': '100'},
{'0': '250'},
{'0': '500'},
{'0': '750'},
{'0': '1000'},
{'0': '2500'},],
[{'1': 'abc|xyz'}],
[{'2': 'Color|purple'}, {'2': 'Color|black'}],
[{'3': 'yes|no'},
{'3': 'no|yes'}],
[{'4': 'Round|no'}, {'4': 'Round|yes'}],
[{'5': 'time|4-5'}],
[{'Base': 'gl'}],
[{'Type': '123'}]]
The number of values elements may change, not all the time will have this length - 8 elements, so I need to handle that as well.
I need to return a list with all combinations possible: Here's an example of an element from the list which I need:
[{'0': '25'}, {'1': 'abc|xyz'}, {'2': 'Color|purple'}, {'3': 'yes|no'}, {'4': 'Round|no'}, {'5': 'time|4-5'}, {'Base': 'gl'}, {'Type': '123'}]
The length of each element from resulted list has to be equal with the length on input list (value in my case).
I tried itertools.permutation
but is giving me more results than I need. Also, I tried @markcial suggestion but it doesn't work if I don't know the length of the input list before hand.