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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Python
  3. Itertools
  4. itertools.product()
  5. Discussions

itertools.product()

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 590 Discussions, By:

recency

Please Login in order to post a comment

  • alihezarpisheh
    1 week ago+ 0 comments
    # without using itertools
    
    def cartesian_product(a, b):
        list1 = list(map(int, a.split()))
        list2 = list(map(int, b.split()))
    
        result = list((n, m) for n in list1 for m in list2)
        print(*result, end=" ")
        # end=" " in print function will create the output in one line
                
                
    firstLine = input()
    secondLine = input()
    
    cartesian_product(firstLine, secondLine)
    
    # using itertools
    
    # from itertools import product
    
    # list1 = list(map(int, input().split()))
    # list2 = list(map(int, input().split()))
    
    # print(*list(product(list1, list2)))
        
    
    0|
    Permalink
  • ParulSharma024
    1 week ago+ 1 comment

    PYYTHON 3

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    from itertools import product
    A, B = map(int, input().split()), map(int, input().split())
    print(*product(A,B))
    
    0|
    Permalink
  • sushant_14
    2 weeks ago+ 0 comments

    x=[int(x) for x in input().split()] y=[int(x) for x in input().split()] print(*product(x,y))

    0|
    Permalink
  • rptl2803
    2 weeks ago+ 1 comment
    from itertools import product
    A, B = list(map(int,input().split())),list(map(int,input().split()))
    print(*product(A,B))
    
    0|
    Permalink
  • tsaxena21
    2 weeks ago+ 0 comments

    from itertools import product

    A = [] [A.append(list(map(int, input().split()))) for _ in range (2)] print(*product(*A))

    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy