Python beginner confused by a complex line 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:53 UTC
        
        
        Read the original article
        Hit count: 365
        
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