也許標題似乎很奇怪,但我bloqued某些時段進行搜尋如何創建這種情況的循環:如何在python中爲這種情況創建一個for循環?
我有這種格式列表的列表:
data=[['nature', author1, author2, ...author n]
['sport', author1, author2, ....author n]
....
]
我有嘗試這種代碼:
authors=[author1, author2, ...author n]
for i in range(len(authors)):
data = [['nature', function(names[i], 'nature')],
['sport', function(names[i], 'sport')
..]
但不幸的是我想它返回以下格式的結果:
data=[['nature', author1]
['sport', author1]
....
]
你能更清楚你的慾望輸出是什麼嗎? – MooingRawr
我的願望輸出是fisrt代碼,但有一個for循環 –
給我幾分鐘我會給你一個工作代碼的例子。我不明白你面臨的挑戰是什麼。也許我的代碼將清除它。你有什麼Python版本?我在3.5上只是想確保我的代碼在你的結尾工作。 –