Computes the cartesian product in Python

Computes the cartesian product in Python

Instructor-svgAl-Mamun Sarkar
Mar 26 , 2020

Computes the cartesian product in Python. The following shows how to solve the HackerRank itertools.product() Python itertools problem.

Code:

from itertools import product

A = list( map( int, input().split() ) )
B = list( map( int, input().split() ) )

print( *list(product(A, B)) )

 

Test Input:

 1 2
 3 4

Test Output:

 (1, 3) (1, 4) (2, 3) (2, 4)
  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram