5 回答

TA贡献1836条经验 获得超5个赞
您要做的是“展平”元组列表。最简单和最 pythonic 的方法是简单地使用(嵌套)理解:
tups = [('1st',), ('2nd',), ('3rd',), ('4th',)]
tuple(item for tup in tups for item in tup)
结果:
('1st', '2nd', '3rd', '4th')
如果确实需要,可以将生成的元组包装在列表中。

TA贡献1862条经验 获得超7个赞
似乎这样可以做到:
import itertools
tuples = [('1st',), ('2nd',), ('3rd',), ('4th',)]
[tuple(itertools.chain.from_iterable(tuples))]

TA贡献1820条经验 获得超10个赞
>>> l = [('1st',), ('2nd',), ('3rd',), ('4th',)]
>>> list(zip(*l))
[('1st', '2nd', '3rd', '4th')]

TA贡献1820条经验 获得超3个赞
简单的解决方案:
tups = [('1st',), ('2nd',), ('3rd',), ('4th',)]
result = ()
for t in tups:
result += t
# [('1st', '2nd', '3rd', '4th')]
print([result])
添加回答
举报