• 第三方库
import itertools as it
a = [-1,0,1,2,-1,4]
result = set(it.combinations(a,r=3))

 

def PowerSetsBinary(items):
    N = len(items)
    res =[]
    for i in range(2 ** N):#子集的个数
        combo = []
        for j in range(N):#用来判断二进制数的下标为j的位置的数是否为1
            if (i >> j) & 1: # 判断是否为1
                combo.append(items[j])
        if not combo: continue # 去掉[]
        res.append(combo)
    return res

 

相关文章:

  • 2022-12-23
  • 2020-02-24
  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2023-01-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案