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條經驗 獲得超2個贊
簡單的解決方案:
tups = [('1st',), ('2nd',), ('3rd',), ('4th',)]
result = ()
for t in tups:
result += t
# [('1st', '2nd', '3rd', '4th')]
print([result])
添加回答
舉報