def p(l): if not l: return [[]] return p(l[1:]) + [[l[0]] + x for x in p(l[1:])]