给定一个集合,元素均为正整数且不重复,求该集合的所有子集
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 10 09:04:53 2017 @author: nvidia
""" #!/usr/bin/python
#coding=utf-8
#求一个集合的所有真子集
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([3,4,5],li)
li.sort()
print li #以上为第二题答案
#after charging ,it was all right! """
the down words are the result!
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
Type "copyright", "credits" or "license" for more information. IPython 2.4.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
%guiref -> A brief reference about the graphical user interface. In [1]: runfile('/home/nvidia/Documents/work/20171010.py', wdir='/home/nvidia/Documents/work')
[[3], [3, 4], [3, 5], [4], [4, 5], [5]] In [2]: """