Permutations of list of lists

Sunday, July 6, 2014

Supposing there is a list of list of elements. Where each list can have any no of elements. For example [[1,2,3,4],[2,3],[4,5,6,7],[1]] . I am trying to generate permutations of such lists possible where I am supposed to select only one from the innermost lists in one such permutation. So the output will be [1,2,4,1],[1,3,4,1]...

Sample Input= [[1,2],[3],[4]] Sample output = [[1,3,4],[2,3,4]]

I had tried some code earlier which had a flawed logic. Following is the code in which I am mid way and stuck. I am no able to get an approach to it. I am not good at Permutations and Combinations.

what I am trying is the same as described above just that the following are set of coordinates. i,e the innermost elements(in input) are set of coordinates.


def perm(a,length):
while (k<length):
for i in a:


Please let me know for further clarifications. Any help is appreciated.