1

[Beginner]

I went through tons of websites, watched tutorials at stretch, everything went in vain.

I stuck with recursion, cannot write/understand beyond writing Factorial of a number using recursion.

I'm trying to understand how combination of a list works

def permute(a, l, r):
    if l==r:
        print a
    else:
        for i in xrange(l,r+1):
            a[l], a[i] = a[i], a[l]
            permute(a, l+1, r)
            a[l], a[i] = a[i], a[l] 


string = "ABC"
n = len(string)
a = list(string)
permute(a, 0, n-1)

How recursion works in the above script/program? Genuinely looking for an answer.

Thank you.

0 Answers0