- Related Questions & Answers
- Python program to get all subsets of a given size of a set
- Print all subsets of given size of a set in C++
- Find all distinct subsets of a given set in C++
- Python Program to Create a Class and Get All Possible Subsets from a Set of Distinct Integers
- C++ Program to Generate All Subsets of a Given Set in the Lexico Graphic Order
- How to find all subsets of a set in JavaScript?
- C++ Program to Generate All Pairs of Subsets Whose Union Make the Set
- Sum of all subsets of a set formed by first n natural numbers
- Count number of subsets of a set with GCD equal to a given number in C++
- Python Program to print all permutations of a given string
- Python program to reverse an array in groups of given size?
- C++ Program to Implement the Binary Counting Method to Generate Subsets of a Set
- Python program to print all distinct elements of a given integer array.
- Check if is possible to get given sum from a given set of elements in Python
- Sum of XOR of all possible subsets in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this article, we will learn about the solution to the problem statement given below.

**Problem statement **− We are given two integers, we need to display the common divisors of two numbers

Here we are computing the minimum of the two numbers we take as input. A loop to calculate the divisors by computed by dividing each value from 1 to the minimum computed.

Each time the condition is evaluated to be true counter is incremented by one.

Now let’s observe the concept in the implementation below−

# built-in module import itertools def findsubsets(str_, n): return list(itertools.combinations(s, n)) # Driver Code str_ = {'t','u','t','o','r'} n = 2 print(findsubsets(str_, n))

[('u', 'r'), ('u', 'o'), ('u', 't'), ('r', 'o'), ('r', 't'), ('o', 't')]

# using combinations function in itertools from itertools import combinations def findsubsets(str_, n): return list(map(set, itertools.combinations(s, n))) str_ = {'t','u','t','o','r'} n = 3 print(findsubsets(str_, n))

[{'u', 'o', 'r'}, {'u', 'r', 't'}, {'u', 'o', 't'}, {'o', 'r', 't'}]

# using combinations function in itertools and appending in a new list def findsubsets(str_, n): return [set(i) for i in itertools.combinations(s, n)] str_ = {'t','u','t','o','r'} n = 3 print(findsubsets(str_, n))

[{'u', 'o', 'r'}, {'u', 'r', 't'}, {'u', 'o', 't'}, {'o', 'r', 't'}]

All the variables are declared in the local scope and their references are seen in the figure above.

In this article, we have learned about python object comparison by using equality & the referencing operator(is).

Advertisements