We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Itertools
- itertools.product()
- Discussions
itertools.product()
itertools.product()
Sort by
recency
|
832 Discussions
|
Please Login in order to post a comment
from itertools import product
A =list(map(int,input().split())) B =list(map(int,input().split()))
for i in product(A, B): print(i,end=" ")
from itertools import product
A = set(input().split()) A = list(sorted((map(int,A)))) B = set(input().split()) B = list(sorted((map(int,B))))
def itertools_product(X,Y): for i in product(X,Y): print(i, end=' ')
result = itertools_product(A,B)
Just to note that the specification says 0 < A < 30 and 0 < B < 30. At least one test case includes values of A that are 0 and if your code does not produce the cartesian product anyway it is marked wrong. Harrumph.
from itertools import product
A = list(map(int,input().split())) B = list(map(int,input().split()))
ans = list(product(A,B)) for i in ans: print(f"{i}",end=" ")
A = sorted(map(int,input().split())) B = sorted(map(int,input().split()))
cartesian_product = [(a, b) for a in A for b in B]
print(" ".join(f"({a}, {b})" for a, b in cartesian_product))