Skip to main content
 首页 » 编程设计

python之连接列表中的元组

2025年05月04日11lyhabc

我想加入列表中的一组元组。

例如,

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

会变成

[123, 124, 125]  
 
(or ['123', '124', '125'] if it must become a string) 

我不知道该怎么做,搜索也没什么用。

我该怎么做?

请您参考如下方法:

>>> bs = [(1, 2, 3), (1, 2, 4), (1, 2, 5)] 
 
>>> ["".join(map(str, b)) for b in bs] 
['123', '124', '125'] 

如果结果必须是数字,使用int()进行转换