Liana
Liana

Reputation: 314

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?

Upvotes: 0

Views: 333

Answers (2)

alireza yazdandoost
alireza yazdandoost

Reputation: 774

you can do it like this:

print(str(list(product(list_A, list_B)))[1:-1])

Upvotes: 1

Z Li
Z Li

Reputation: 4318

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)

Upvotes: 2

Related Questions