I am writing a program to return a set of subset of number.
For example: list = [1,2,3]
my desired function will return [[], [1], [2], [2,1], [3], [3,1], [3,2], [3,2,1]]
However, it returns [[], [1], [2], [3]]
Here is my code
# Write a powerSet function
def powerSet(list):
if len(list) == 0:
return [[]];
else:
temp = list.pop()
return powerSet(list) + [[temp] + x for x in powerSet(list)];
list = [1,2,3];
print(powerSet(list));
listis a built-in, hence a poor choice for a variable name. Also --pop()destructively mutates the passed list -- you should be modifying copies of it.