求一个集合的所有真子集 Python 2.7.6编译,python2.7.6,getRealSubSe


getRealSubSet(fromList,toList)

fromList:要求的集合

toList:用来储存fromList所有真子集的

def getRealSubSet(fromList,toList):    if(len(fromList) <= 1):        return    for id in range(len(fromList)):        arr = [i for i in fromList if i != fromList[id]]        getRealSubSet(arr,toList)        #print arr        if(toList.count(arr) == 0):            toList.append(arr)li = []getRealSubSet([1,2,3,4],li)li.sort()print li#该片段来自于http://byrx.net

评论关闭