﻿ Python: Get all possible unique subsets from a set of distinct integers - w3resource

# Python: Get all possible unique subsets from a set of distinct integers

## Python Class: Exercise-4 with Solution

Write a Python program to get all possible unique subsets from a set of distinct integers.

Sample Solution:

Python Code:

``````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]))
```
```

Sample Output:

```[[], [6], [5], [5, 6], [4], [4, 6], [4, 5], [4, 5, 6]]
```

Pictorial Presentation:

Flowchart:

## Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Contribute your code and comments through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿

## Python: Tips of the Day

Free up Memory:

• Manual garbage collection can be performed on timely or event based mechanism.
```import gc
collected_objects = gc.collect()
```

We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook