2017-04-14 41 views
2

我有以下存儲在變量resultset
([「詹姆斯·泰勒」],[「薩拉·賈羅斯斯」],[「歪還是」])Python的轉換列表的元組列表

我會喜歡將其重寫爲列表,即['James Taylor','Sarah Jarosz','彎曲靜止']。

我該怎麼辦?在此先感謝

+4

可能的重複[在Python中使列表成爲列表](http://stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-列舉式的Python)。我知道你的情況有一個元組而不是一個列表,但列出的解決方案適用。還有很多其他類似的問題,像這樣:http://stackoverflow.com/questions/18500541/how-to-flatten-a-tuple-in-python – Bahrom

回答

1

如果這是不是其實是一個重複:

resultset = (['James Taylor'], ['Sarah Jarosz'], ['Crooked Still']) 
new_list = [i[0] for i in resultset] 
print new_list 

[「詹姆斯·泰勒」,「薩拉·賈羅斯斯」,「歪斯蒂爾]

+0

正是我在找什麼,謝謝! –

1

您還可以使用:

l = (['James Taylor'], ['Sarah Jarosz'], ['Crooked Still']) 
new_l = [item for sublist in l for item in sublist] 
相關問題