I had such a hard time figuring out how to write a python function to generate permutations two weeks ago.
Then yesterday, I tried doing it again using a different method and I got stuck for half an hour. It finally worked when I used list.extend instead of list.append.
And then when I looked at the code I wrote two weeks ago, they were the exact same. Recursion within a for-loop. Damn. This site very helpfully explained the thinking: http://typeocaml.com/2015/05/05/permutation/
for index,num in enumerate(input):
to_add=[[num]+ result for result in permutate(remain)]