itertools.product()

Sort by

recency

|

817 Discussions

|

  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import itertools
    
    # Taking input for list A
    A = list(map(int, input().split()))
    
    # Taking input for list B
    B = list(map(int, input().split()))
    
    
    cartesian_product = list(itertools.product(A, B))
    
    for pair in cartesian_product:
        print(pair, end=" ")
    
  • + 0 comments

    from itertools import product

    a = list(map(int, input().split())) b = list(map(int, input().split())) for i in (list(product(*[a,b]))): print(i,end=" ")

  • + 0 comments

    Python 3, input from STDIN

    from itertools import product
    import sys
    
    arr = []
    for line in sys.stdin.readlines():
        i = map(int, line.split())
        arr.append(i)
    
    for i in product(*arr):
        print(i, end=' ')
    
  • + 0 comments
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    
    li=[]
    for i in a:
        for j in b:
            li.append((i,j))
    
    for i in range(len(li)):
        print(li[i],end=" ")
            
    
  • + 0 comments
    a, b = list(map(int, input().split())), list(map(int, input().split()))
    
    l = [(x, y) for x in a for y in b]
    
    print(*l)