a = [0, 1, 2, 3]
lena = len(a)
sum = []
for i in range(2 ** lena):
comb = []
for j in range(lena):
if (i >> j) % 2 == 1:
comb.append(a[j])
sum.append(comb)
print(sum)
结果
[[], [0], [1], [0, 1], [2], [0, 2], [1, 2], [0, 1, 2], [3], [0, 3], [1, 3], [0, 1, 3], [2, 3], [0, 2, 3], [1, 2, 3], [0, 1, 2, 3]]