Python program to find cartesian product of two sets.

Cartesian product of two sets, Let’s consider we have setA = {3, 5} and setB = {6, 7} then the Cartesian product of two sets will be {(3, 6), (3, 7), (5, 6), (5, 7)}

Cartesian product of two sets with Python

Steps to solve the program

1. Initiate two sets setA and setB.
2. Initiate a result set where we will add the combined value of setA and setB.
3. Apply a nested loop, the first loop will pick the value of setA and the second loop will value of setB.
4. Combine setA and setB values in the tuple and add them to the result set. 
5. Print result set.

Output :  Cartesian product of two sets values.

Related Articles

create two sets of books and find the intersection of sets.

Leave a Comment