Hackerrank itertools.product() | Solution

admin
By -
0

 This simple question here we just need to  take arguments user input for our Two List A and B each with single line means two lines and cause its integer show we need to  a way we can take  it in single line space and put to list to  store 

and after this we just need to pass them  to  itertools  ,  function product  where it gives use cartesian values of  this two  coordinate list  items via compute them and remembered this product function gives use return as binary machine code  so  you  need to  use list()  within to  convert it  human read able 



now the output cause its gives use tuples items which stored in products lists so  we need to  print them  into  single line  with space separated for that  way  we used last line code end=" "

We used list and map  so  we can take multiple integer values in single line user input with space separated.


Problem: https://www.hackerrank.com/challenges/itertools-product/problem?isFullScreen=true

Code:

# Enter your code here. Read input from STDIN. Print output to STDOUT
from itertools import product
A = list(map(int , input().split()))
B = list(map(int , input().split()))
products = list(product(A,B))

for item in products: print(item, end=" ") # To print in single line





Post a Comment

0Comments

Please Select Embedded Mode To show the Comment System.*