自定义电源设置功能



我正在尝试在python中执行此代码,并且编译没有错误。但是,我在变量资源管理器中看不到变量 z。我正在尝试创建一个函数来提供输入集的所有子集。

import numpy as np
import itertools as itt
def powerset(iterable):
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
s = list(iterable)
return itt.chain.from_iterable(itt.combinations(s, r) for r in 
range(len(s)+1))
def powerset_generator(i):
for subset in itt.chain.from_iterable(itt.combinations(i, r) for r in 
range(len(i)+1)):
yield set(subset)
z=powerset({1,2,3})

简单的功率设置函数

import math 
def powerSet(LIST,SIZE): 
sizeOfAll = (int) (math.pow(2, SIZE))
i = 0
store = 0
print("Φ")
for i in range(1, sizeOfAll):
store = format(i,'0'+str(SIZE)+'b')
j=0
for j in range(0,SIZE):
if store[j] == '1':
print(LIST[j],end="")
print()
powerSet(['a', 'b', 'c','d'], 4)

最新更新