python3 求一个list的所有子集

def PowerSetsBinary(items):
    N = len(items)
    for i in range(2 ** N):#子集的个数
        combo = []
        for j in range(N):#用来判断二进制数的下标为j的位置的数是否为1
            if (i >> j) % 2:
                combo.append(items[j])
        print(sum(combo))
        print(combo,"\n")

        
L = [100000,12844.26,11393.83,14819.92,747.04,843,30435.12,3628.48,40856.32,12326.16,20259.01,16360.18,26146.4,4268.8,6403.2,5015.84,41366.51,6819.48,15061.12,31887.67,28590.49,63716.64,9469.35,12749.43,16346.4,100000,23557.22,1067.2,192.1,533.6]
print(round(sum(L),2))
#PowerSetsBinary(L)

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄