programming-examples/python/Class/Python program to get all possible unique subsets from a set of distinct integers.py

10 lines
365 B
Python
Raw Normal View History

2019-11-15 12:59:38 +01:00
class py_solution:
def sub_sets(self, sset):
return self.subsetsRecur([], sorted(sset))
def subsetsRecur(self, current, sset):
if sset:
return self.subsetsRecur(current, sset[1:]) + self.subsetsRecur(current + [sset[0]], sset[1:])
return [current]
print(py_solution().sub_sets([4,5,6]))