-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowSet.py
More file actions
18 lines (15 loc) · 726 Bytes
/
Copy pathPowSet.py
File metadata and controls
18 lines (15 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"""This program computes the power set given a set of elements"""
## METHODE ONE
def PowSet(Set): ##Set is a list object
"""return the power set of the given set of elements"""
powSet = [[],Set] #intialise the power set with the empty set and the set itself
powSet = [[item] for item in Set] #add every element in given set as subset in power set
size = len(Set) #initialize length of Set
for indx in range(len(Set)):
while True:
if not(Set[indx:indx+2] in powSet): break ##indx + 1!= len(Set) and not(
powSet.append(Set[indx:size]) ##
size = size-1 ##decrement size
return powSet
print(PowSet([1,2,3]))
"""This is a working Progress"""