gpt4 book ai didi

python - 连接列表中的元组

转载 作者:太空宇宙 更新时间:2023-11-04 07:23:19 25 4
gpt4 key购买 nike

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

例如,

[(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()进行转换

关于python - 连接列表中的元组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11373584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com