[英]How to make the brackets surrounding tuple elements of a list disappear in stdout
我编写了以下代码:
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)))
样本输入
1 2
3 4
代码 Output
[(1, 3), (1, 4), (2, 3), (2, 4)]
我怎样才能让两个括号消失,而是让(1, 3), (1, 4), (2, 3), (2, 4)
成为 output?
本质上您是在问如何打印列表但删除两端的括号:
l = [(1,2), (3,4)]
print(', '.join(map(str, l)))
output:
(1, 2), (3, 4)
你可以这样做:
print(str(list(product(list_A, list_B)))[1:-1])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.