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

Description:
To get all possible subsets from a given set of integers, we can implement the built-in combination function in the itertools library.
The method: combinations(iterable, r) returns successive r-length combinations of elements in the iterable.
Therefore if a set contains 3 integers, we can have subsets of length 0, 1, 2 and 3.

Python Code:
import itertools class Subsets: def __init__(self, integers): self.integers = integers def get_subsets(self): subsets = [] for i in range(len(self.integers)+1): for element in list(itertools.combinations(self.integers, i)): subsets.append(element) return subsets def main(): integers = set(map(int, input("Enter a set of distinct integers: ").split(' '))) obj = Subsets(integers) possible_subsets = obj.get_subsets() for subset in possible_subsets: print(subset) if __name__ == "__main__": main()

Output:
Enter a set of distinct integers: 1 2 3 () (1,) (2,) (3,) (1, 2) (1, 3) (2, 3) (1, 2, 3)

#### More Articles of Siddhartha Dutta:

Name Views Likes
Python Program to Get a Function from a C Program File 444 0
Python DynamoDB Delete a Table 485 0
Python DynamoDB Scan the Table 751 0
Python DynamoDB Query the Table 544 0
Python DynamoDB Delete a Record 482 0
Python DynamoDB Update an Existing Record 500 0
Python DynamoDB Read a Record 403 0
Python DynamoDB Insert Multiple Records into Table 662 0
Python DynamoDB Insert Record into Table 386 0
Python DynamoDB Create Table 434 0
Python DynamoDB Get Started 508 0
Python Program to Test Hard Disk Speed 477 0
GUI based Python Program to Count Number of Characters 388 0
GUI based python application to count number of characters 453 3
Python MySQL prevent SQL injection in update 557 0
Python MySQL prevent SQL injection in delete 442 0
Python MySQL prevent SQL injection in select 1004 0
Python MySQL join two tables 471 0
Python MySQL limit the number of records in a table 503 0
Python MySQL update existing record 396 0
Python MySQL drop table only if exist 399 0
Python MySQL drop table 386 0
Python MySQL delete record 378 0
Python MySQL sort the result in ascending order 367 0
Python MySQL sort the result in descending order 424 0
Python MySQL sort the result 381 0
Python MySQL Order By 402 0
Python MySQL wildcard select 389 0
Python MySQL select with a Filter 390 0
Python MySQL where example and usage 575 0
Python MySQL select using fetchone method 365 0
Python MySQL select particlular column from table 359 0
Python MySQL select from table 0 0
Python MySQL insert record into table and get inserted ID 393 0
Python MySQL insert multiple records into table 435 0
Python MySQL insert record into table 370 0
Python MySQL create table 364 0
Python MySQL check database exists or not 632 5
Python MySQL create database 397 11
Python MySQL connector get started 416 10
Python MongoDB Limit the Result 585 10
Python MongoDB Update Many Records 542 10
Python MongoDB Update Record 516 10
Python MongoDB Drop Collection 456 10
Python MongoDB Delete All Documents in a Collection 533 10
Python MongoDB Delete Many Documents 478 10
Python MongoDB Delete Document 415 10
Python MongoDB Sort the result in descending order 422 10
Python MongoDB Sort the Result 411 10
Python MongoDB Query Filter With Regular Expressions 466 10
Python MongoDB Query Filter the Result 437 10
Python MongoDB Select specific fields from collection 448 10
Python MongoDB Select all data from collection using find method 524 10
Python MongoDB Select data from collection using find_one method 436 10
Python MongoDB Insert Multiple Documents, with Specified IDs 410 10
Python MongoDB Insert Multiple Documents 417 10
Python MongoDB Insert Into Collection and return the _id field 430 10
Python MongoDB Insert Into Collection 439 10
Python MongoDB Check if Collection Exists 2538 10
Python MongoDB Creating a Collection 580 10
Python MongoDB Check if Database Exists 657 10
Python MongoDB Creating a Database 521 20
Python MongoDB Get Started 575 21
Python Program to Convert a given Singly Linked List to a Circular List 258 10
Python Program to Check whether a Singly Linked List is a Palindrome 1306 10
Python Program to Illustrate the Operations of Singly Linked List 248 10
Python Program to Support Infinite Precision Arithmetic & Store a Number as a List of Digits 230 10
Python Program to Interchange the two Adjacent Nodes given a circular Linked List 239 10
Python Program to Interchange two Elements of the List without touching the Key Field 241 10
Python Program to Solve Josephus Problem using Linked List 1118 10
Python Program to Implement Shell Sort 301 10
Python Program to Implement Comb Sort 309 10
Python Program to Implement Cocktail Shaker Sort 477 10
Python Program to Implement Gnome Sort 435 11
Python Program to Find the Sum of All Nodes in a Binary Tree 701 10
Python Program To Find the Smallest and Largest Elements in the Binary Search Tree 310 10
Python Program to Implement Priority Queue to Add and Delete Elements 254 10
Python Program to Implement Dequeue 323 10
Python Program to Flatten a List without using Recursion 243 10
Python Program to Flatten a Nested List using Recursion 613 10
Python Program to Convert a Binary Tree into a Singly Linked List by Traversing Level by Level 547 10
Python Program to Find the Total Sum of a Nested List Using Recursion 1378 10
Python Program to Print the Alternate Nodes in a Linked List using Recursion 278 10
Python Program to Print the Alternate Nodes in a Linked List without using Recursion 254 10
Python Program to Implement Selection Sort 248 10
Python Program to Find Number of Occurrences of All Elements in a Linked List 304 16
Python Program to Display the Nodes of a Linked List in Reverse using Recursion 302 13
Python Program to Display the Nodes of a Linked List in Reverse without using Recursion 312 11
Python Program to Check String is Palindrome using Stack 411 14
Python Program to Read the Contents of a File in Reverse Order 379 20
Python Program to Count the Number of Blank Spaces in a Text File 305 16
Python Program to Read a Text File and Print all the Numbers Present in the Text File 474 12
Python Program that Reads a Text File and Counts the Number of Times a Certain Letter Appears in the Text File 531 27
Python Program to Count the Number of Vowels Present in a String using Sets 474 20
Python Program to Find the Second Largest Number in a List Using Bubble Sort 336 19
Python Program to Find the Length of a List Using Recursion 320 12
Python Program to Check if Expression is correctly Parenthesized 294 18
Python Program to Find the Fibonacci Series without Using Recursion 1030 27
Python Program to find the factorial of a number without recursion 326 27
Python Program to Reverse a String without using Recursion 561 28
Python Program to Find the Binary Equivalent of a Number without Using Recursion 259 15
Python Program to Find All Numbers which are Odd and Palindromes Between a Range of Numbers without using Recursion 342 23
Python Program to Find the Sum of Digits in a Number without Recursion 325 23
Python Program to Sort the List According to the Second Element in Sublist 376 17
Python Program to Append, Delete and Display Elements of a List Using Classes 1371 22
Python Program to Find the Area of a Rectangle Using Classes 299 18
Python Program to Create a Class and Get All Possible Subsets from a Set of Distinct Integers 446 31
Python Program to Create a Class in which One Method Accepts a String from the User and Another Prints it 352 15
Python Program to Create a Class which Performs Basic Calculator Operations 290 17
Python Program to Create a Class and Compute the Area and the Perimeter of the Circle 292 19
Python Program that Displays which Letters are in the First String but not in the Second 264 19
Python Program to Sort a List According to the Length of the Elements 300 18
Python Program to Compute a Polynomial Equation given that the Coefficients of the Polynomial are stored in a List 1134 24
Python Program to Find the Sum of the Digits of the Number Recursively 293 21
Python Program to Find the Binary Equivalent of a Number Recursively 287 20
Python Program to Find the Sum of Elements in a List Recursively 269 19
Python Program to Find the Factorial of a Number Using Recursion 216 19
Python Program to Find the Fibonacci Series Using Recursion 298 28
Python Program to Determine How Many Times a Given Letter Occurs in a String Recursively 367 12
Python Program to Determine Whether a Given Number is Even or Odd Recursively 249 14
Python Program to Put Even and Odd elements in a List into Two Different Lists 454 20
Python Program to Find the Second Largest Number in a List 220 16
Python Program to Find the Largest Number in a List 346 22
Python Program to Clear the Rightmost Set Bit of a Number 410 22
Python Program to Count Set Bits in a Number 238 15
Python Program to test Collatz Conjecture for a Given Number 474 18
Python Program to Search the Number of Times a Particular Number Occurs in a List 226 14
Python Program to Determine all Pythagorean Triplets in the Range 355 18
Python Program to Find the Sum of First N Natural Numbers 276 19
Python Program to Find the Sum of Cosine Series 838 18
Python Program to Find the Sum of Sine Series 1202 20
Python Program to Check If Two Numbers are Amicable Numbers 240 17
Python Program to Find the LCM of Two Numbers 345 31
Python Program to Check if a Number is a Strong Number 226 20
Python Program to Find Those Numbers which are Divisible by 7 and Multiple of 5 in a Given Range of Numbers 221 17
Python Program to Print Sum of Negative Numbers, Positive Even Numbers and Positive Odd numbers in a List 318 11
Python Program to Compute Prime Factors of an Integer 351 28
Python Program to Check if a Date is Valid and Print the Incremented Date if it is 848 22
Python Program to Print an Inverted Star Pattern 661 20
Python Program to Implement Binary Insertion Sort 299 13
Python Program to Implement Insertion Sort 246 20
Python Program to Implement Binary Search with Recursion 202 19
Python Program to Implement Binary Search without Recursion 302 22
Python Program to Implement Linear Search 276 24
Python Program to Sort using a Binary Search Tree 260 18
Python Program to Generate Random Numbers from 1 to 20 and Append Them to the List 319 26
Python Program to Print an Identity Matrix 233 16
Python Program to Read a Number n and Print the Natural Numbers Summation Pattern 392 26
Python Program to Read a Number n And Print the Series 1+2+.....+n= 274 28
Python Program to Print Odd Numbers Within a Given Range 283 26
Python Program to Accept Three Digits and Print all Possible Combinations from the Digits 454 19
Python Program to Read Two Numbers and Print Their Quotient and Remainder 836 30
Python Program to solve Maximum Subarray Problem using Kadanes Algorithm 350 18
Python Program to Exchange the Values of Two Numbers Without Using a Temporary Variable 237 15
Python Program to Find Element Occurring Odd Number of Times in a List 230 20
Python Program to Replace all Occurrences of a with a \$ in a String 288 17
Python Program to Remove the nth Index Character from a Non-Empty String 765 16
Python Program to Check if a Substring is Present in a Given String 283 20
Python Program to Count the Occurrences of Each Word in a Given String Sentence 345 19
Python Program to Form a New String Made of the First 2 and Last 2 characters From a Given String 244 15
Python Program to Calculate the Number of Digits and Letters in a String 372 13
Python Program to Check if a String is a Pangram or Not 316 20
Python Program to Calculate the Number of Upper Case Letters and Lower Case Letters in a String 1771 21
Python Program to Check if a String is a Palindrome or Not 228 11
Python Program to Count Number of Lowercase Characters in a String 243 19
Python Program to Take in Two Strings and Display the Larger String without Using Built-in Functions 265 18
Python Program to Calculate the Number of Words and the Number of Characters Present in a String 246 19
Python Program to Remove the Characters of Odd Index Values in a String 968 23
Python Program to Calculate the Length of a String Without Using a Library Function 248 21
Python Program to Take in a String and Replace Every Blank Space with Hyphen 555 25
Python Program to Count the Number of Vowels in a String 234 23
Python Program to Detect if Two Strings are Anagrams 285 22
Python Program to Form a New String where the First Character and the Last Character have been Exchanged 683 12