itertools.product()

Sort by

recency

|

832 Discussions

|

  • + 0 comments

    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=" ")

  • + 0 comments

    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)

  • + 0 comments

    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.

  • + 0 comments

    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=" ")

  • + 0 comments

    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))