I have a code that uses recursion to calculate the permutation of the characters of a string. I understand normal tail recursion and recursions for palindrome, factorial, decimal to binary conversion easily but i am having problem understanding how this recursion works, i mean how it actually works in the background, not just the abstract stuff from the higher level i get that.
here is the code
from __future__ import print_function
def permutef(s):
#print('\nIM CALLED\n')
out = []
if len(s) == 1:
out = [s]
else:
for i,let in enumerate(s):
#print('LETTER IS {} index is {}'.format(let, i))
#Slicing as not including that letter but includes every letter except that to perform the permutation
for perm in permutef( s[:i] + s[i+1:] ):
print(perm)
out += [let + perm]
return out
per = permutef('abc')
print('\n\n\n', per, '\n\n\n')
I was writing in a paper each circle is for each letter and how the corresponding stack pops
Don't ask about my handwriting i know its awesome (sarcasm)
here is the output screenshot
i want to understand the nitty gritty about how this works in the background, but i can't seem to fathom the concept, very very thanks in advance.

