In this HackerRank itertools.product() problem solution in python we need to develop a python program that can read two lists separated on each line and then we need to print the all possible product on the output screen.
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)))
0 Comments