def perm(L): if not L: return [] elif len(L)==1: return [list(L)] else: return [[L[i]]+P for i in range(len(L)) for P in perm(L[:i]+L[i+1:])]