我在 Python 中有這些串列
text_0 = ['Weight','Weight', 'Weight']
text_1 = [['x','y','z'],['x','y','z'],['x','y','z']]
text_2 = [['1','2,','3'],['4','5','6'],['7','8','9']]
我想創建一個這樣的新串列
new_list = ['Weight','x','1','y','2','z','3','Weight','x','4','y','5','z','6','Weight','x','7','y','8','z','9']
我如何在 Python 中做到這一點?
uj5u.com熱心網友回復:
在你的情況下,我們可以做 python
sum([[x] [ items for item in zip(y,z) for items in item]
for x, y, z in zip(text_0,text_1,text_2)],[])
['Weight', 'x', '1', 'y', '2', 'z', '3', 'Weight', 'x', '4', 'y', '5', 'z', '6', 'Weight', 'x', '7', 'y', '8', 'z', '9']
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/392895.html
標籤:蟒蛇-3.x
上一篇:創建子字典鍵值對的笛卡爾積
