# All pair combinations of 2 tuples in Python

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

When it is required to find all the pair combinations between two tuples, the list comprehension can be used.

Below is the demonstration of the same −

## Example

Live Demo

from itertools import product
N = 2
print("The value of N has been initialized to ")
print(N)
my_result = [ele for ele in product(range(1, N + 1), repeat = N)]

print("All tuple combinations until 2 are : " )
print(my_result)

## Output

The value of N has been initialized to
2
All tuple combinations until 2 are :
[(1, 1), (1, 2), (2, 1), (2, 2)]

## Explanation

• The required packages are imported.

• The value of N is set and is displayed on the console.

• The list comprehension is used to iterate over the values up to N, and it is incremented.

• This is assigned to a variable.

• It is displayed as output on the console.