Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerRank itertools.product() solution in python

YASH PAL, 31 July 2024

In this HackerRank itertools.product() problem solution in python This tool computes the cartesian product of input iterables.

It is equivalent to nested for-loops. You are given a two lists A and B. Your task is to compute their cartesian product A X B.

HackerRank itertools.product() solution in python

Problem solution in Python 2 programming.

from itertools import product

A = map(int,raw_input().split())
B = map(int,raw_input().split())
print " ".join(str(k) for k in product(A,B))

Problem solution in Python 3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT

from itertools import product
a = map(int, input().split())
b = map(int, input().split())

print(*product(a, b))

Problem solution in pypy programming.

from itertools import product
flist = map(int, raw_input().split())
slist = map(int, raw_input().split())

for item in product(flist, slist):
    print tuple(item), 

Problem solution in pypy3 programming.

import itertools
# Enter your code here. Read input from STDIN. Print output to STDOUT
A = list(map(int,input().split()))
B = list(map(int,input().split()))

p = list(itertools.product(A,B))
print(" ".join(map(str,p)))

coding problems hackerrank solutions python

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes