如何拆分第二元組拆分元組項目
data = [('152', 'Farko', 'Kier'), ('153', 'Park - Pub')]
得到這個輸出:
[('152', 'Farko', 'Kier'), ('153', 'Park', 'Pub')]
我試着這樣說:
lst = []
for i in data:
if len(i) == 2:
i[1] = tuple(i[1].split(' - '))
lst.append(i)
它會工作,除了它提出異常TypeError: 'tuple' object does not support item assignment
。但是我不能指定i = tuple(i[1].split(' - '))
,因爲我需要保留元組中位置爲i[0]
的數字。列表編譯解決方案將非常受歡迎。建議?