为什么不这样:
def subsets(x):
if not x:
return [[]]
else:
return [x + y for x in [[], [x[0]]] for y in subsets(x[1:])]
print subsets(['a', 'b'])
产生与此相同的输出:
def subsets(x):
if not x:
return [[]]
else:
z = subsets(x[1:])
return [x + y for x in [[], [x[0]]] for y in z]
print subsets(['a', 'b'])