

Now if the elements of L are complex objects, a bookkeeping array of integers is probably smaller than a copy of the elements as formed in R. So you have to remember that the value that was input location 0 is now in input location 8. for indices in permutations(range(n), r): if sorted(indices) list(indices): yield. Another brute force itertools function is permutations(), which accepts a single. list2 6, 7, 9 list3 8, 10, 5 print ('The original lists are : ' + str(list1) +. Note how it just completely loses track of what is going on. 1, 2, 3 and a, b, c, like all lists, are iterable. Note: permutations act on the left by default def init(self,perm,length0,onLeftTrue): The input perm can be a list/tuple of integers. We import the specific function permutations from. from itertools import permutations perms permutations ( 1,2,3,4) for k in list (perms): print k. The post simply shows the way to use it Consider the following program. The output shows what happens if I print the correct solution below what your algorithm computes. Yes, python does have an in-built library function to generate all possible permutations of a given set of elements.


Print()The problem with your swapping method is that once you move "I" to location 0 and swap "A" to location 9, then when you select element 1, that is, index 0, you are selecting the value "I", which is what you put in location 0. I would suggest choosing some random values for L, just type in whatever numbers you feel like, or better still, use letters like I think part of your problem is that you have used a dense set of integers for each list, which makes it hard to see what is going on.
