Sep-10-2018, 01:25 PM
You haven't written a function to generate the permutations. You've written a function to show the permutations. The function returns nothing (or rather, None). The reason you are getting an empty list at the end is that you are assigning p to sortedList. But p is a list, which is a mutable data type. So when you change p, you change sortedList as well. Then you go on to do a bunch of appends and pops to p, which is where I'm guessing it gets emptied.
Don't use global. Use the return statement to return values from your functions. Your recursive function should return a list of permutations. When it gets to the bottom of the recursion, it should return a list containing the permutation it found, with the permutation protected from mutability (either by copying with [:] or making immutable with tuple()). That is return to the next level, where it is extended on to the list that level is returning. Then at the top you will return a full list of permutations that you can sort
Don't use global. Use the return statement to return values from your functions. Your recursive function should return a list of permutations. When it gets to the bottom of the recursion, it should return a list containing the permutation it found, with the permutation protected from mutability (either by copying with [:] or making immutable with tuple()). That is return to the next level, where it is extended on to the list that level is returning. Then at the top you will return a full list of permutations that you can sort
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures