## Example taken from Python Reference Manual ## Beautiful illustration of the logic behind ## Pythonic splices. def perm(l): """Compute the list of all permutations of l""" if len(l) <= 1: return [l] r = [] for i in range(len(l)): # s = l with the ith element skipped. s = l[:i] + l[i+1:] p = perm(s) for x in p: # l[i:1+1]: singleton list onctianing i-th element r.append(l[i:i+1] + x) return r