def nast(L):
i=len(L)-1
while L != [1 for i in range(len(L))]:
if L[i]==0:
L[i]=1
break
i=i-1
for j in range(i+1,len(L)):
L[j]=0
return L
def extr(dss,bb):
for i in list(dss.keys()):
if bb[i]==0:
dss.pop(i)
w=list(dss.values())
return w
def GenSet(ss):
L1=[0 for i in range(len(ss))]
w=[()]
while L1 != [1 for i in range(len(ss))]:
dss=dict(zip([i for i in range(len(ss))],list(ss)))
tL1=tuple(nast(L1))
temp=extr(dss,tL1)
temp1=tuple(temp)
w.append(temp1)
ww= [set(x) for x in w]
return ww, len(ww)
我希望此代码生成 n 元素集的子集。不幸的是,GenSet()既不返回值,也不返回错误;它使 Ipython 的外壳崩溃。