Search code examples
pythonpython-3.xlisttuplespython-itertools

How to make the brackets surrounding tuple elements of a list disappear in stdout


I've written the following code:

from itertools import product

list_A = [int(x) for x in input().split()]
list_B = [int(y) for y in input().split()]

print(list(product(list_A, list_B)))

Sample Input

1 2
3 4

Code Output

[(1, 3), (1, 4), (2, 3), (2, 4)]

How can I make the two brackets disappear and rather get (1, 3), (1, 4), (2, 3), (2, 4) as output?


Solution

  • essentially you are asking how to print a list but remove the brackets on the two ends:

    l = [(1,2), (3,4)]
    
    print(', '.join(map(str, l)))
    

    output:

    (1, 2), (3, 4)