<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">def perm(alist):
    ''' Return all the possible permutations (arrangements) of 
    the items in alist. ''' 
    
    if alist == []:
        return [[]]
    
    subperms = perm(alist[1:])
    
    ret = []
    for p in subperms:
        for i in range(len(p)+1):
            newp = p[:]
            newp.insert(i, alist[0])
            ret.append(newp)
            
    return ret
            
        </pre></body></html>