Python Program to Create a Class and Get All Possible Subsets from a Set of Distinct Integers

In this example, we will write a python program to create a class and get all possible subsets from a set of distinct integers. To better understand this example, make sure you have knowledge of the following tutorials:-

Python Program to Convert temperatures using Classes

The output of the above program is:-

Enter number of elements of list: 3
Enter element: 4
Enter element: 3
Enter element: 7
Subsets:
[[], [7], [4], [4, 7], [3], [3, 7], [3, 4], [3, 4, 7]]
Program Explanation
  • A class named “Subset” is defined that has two methods f1 and f2.
  • The number of elements is taken from the user and using a for loop, the elements of the list are taken.
  • The f1 method of the class is called passing the list as a parameter.
  • The f2 method is a recursive function that generates all the sublist until the list becomes empty.
  • The final result is printed.
SHARE Python Program to Create a Class and Get All Possible Subsets from a Set of Distinct Integers

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Share