So , the problem is not in my code , it is in the output . Also , the problem is stated on Hacker Rank so if you know the solution to it, thanks but I do not need the solution to the original problem , I want my doubt to be cleared. So the problem is
You are given a two lists A and B . Your task is to compute their cartesian product X.
What I have done is ,
from itertools import product
list_A = list(map(int ,input().split()))
list_B = list(map(int ,input().split()))
x = list(product(list_A,list_B))
y = tuple(x)
print(y)
And this gives me the desired output : ((1, 3), (1, 4), (2, 3), (2, 4))
However , HackerRank doesn't seem to want a tuple . So I need to print out the same values , just not as a tuple .
Expected Output (1, 3) (1, 4) (2, 3) (2, 4)
I am sure that the solution to this must be pretty simple however I just can not get my head to it for some reason. All help is appreciated! Thanks!
print(x)print(' '.join([str(z) for z in x]))to get the string outputprint(" ".join(f"{x}" for x in y))print(*x)to pass the list elements as individual arguments to print