dimanche 6 juillet 2014

Permutations of list of lists


Vote count:

0




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.


[[[1,2],[2,4]],[[2,3],[4,2]],[[1,5]],[[3,3],[7,2],[5,6]]]



def perm(a,length):
arr=[]
k=0
while (k<length):
temp=[]
for i in a:


a=[[[1,2],[2,4]],[[2,3],[4,2]],[[1,5]],[[3,3],[7,2],[5,6]]]
perm(a)


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



asked 51 secs ago

RED

57





Aucun commentaire:

Enregistrer un commentaire