Python begineer confused by a piece of code

Posted by Protean on Stack Overflow See other posts from Stack Overflow or by Protean
Published on 2010-04-06T00:34:51Z Indexed on 2010/04/06 0:43 UTC
Read the original article Hit count: 255

Filed under:
|

I understand the gist of the code, that it forms permutations; however, I was wondering if someone could explain exactly what is going on in the return statement.

def perm(l):
    sz = len(l)
    print (l)
    if sz <= 1:
        print ('sz <= 1')
        return [l]
    return [p[:i]+[l[0]]+p[i:] for i in range(sz) for p in perm(l[1:])]

© Stack Overflow or respective owner

Related posts about beginner

Related posts about python