展开全部
def getsubset(myset,subtract):
if len(myset)<=1:
return []
result=[]
newsubtract=subtract.copy()
for i in subtract:
result.append(myset-{i})
newsubtract=newsubtract-{i}
result.extend(getsubset(myset-{i},newsubtract))
return result
def subset(myset):
result=[set(),myset] if myset else [myset]
result.extend(getsubset(myset,myset))
return result
result=subset({'a','b','c','d'})
toprint=[sorted(x) for x in result]
for i in sorted(toprint,key=lambda x:(len(x),x)):
print(i)
虽然这对我来说的确比较简单,可也不是几32313133353236313431303231363533e4b893e5b19e31333335313230分钟就能写出来的,好歹给点分吧
而且(a,b,a,c) 不是集合,集合中元素不应有重复
一个n个元素的集合的所有子集是2的n次方个吗,如是,这个程序应该就是正确的