目前還不清楚你在問什麼......但如果你只是想要一個列表清單,只需追加它們即可。
>>> nested_list.append(EX_Num)
>>> nested_list.append(Height_str)
>>> nested_list.append(total_carbon)
>>> nested_list
[[1.0, 2.0, 3.0], ['tall', 'medium', 'short'], [8.425169446611104, 8.917085904771866, 6.174348482965436]]
如果要將所有值放入一個列表中,只需將它們連接起來即可。
>>> nested_list = EX_Num + Height_str + total_carbon
>>> nested_list
[1.0, 2.0, 3.0, 'tall', 'medium', 'short', 8.425169446611104, 8.917085904771866, 6.174348482965436]
如果你需要不同的東西,你需要讓你的問題更清楚]
編輯基於評論:
如果你知道所有的列表的長度相同:
nested_list = []
# be careful, if the lists aren't all the same length, you will get errors
for x in range(len(EX_Num)):
tmp = [EX_Num[x], Height_str[x], total_carbon[x]]
nested_list.append(tmp)
來源
2015-09-12 21:42:43
jdf
用什麼語言?請閱讀[如何創建最小,完整和可驗證的示例](http://stackoverflow.com/help/mcve)和[我如何提出一個好問題?](http://stackoverflow.com/help/如何對問)。 –
這個問題目前還不清楚,但如果你確實使用python,分號是不必要的,不應該使用。我假設列表3末尾的時間段是一個類型o,但如果不是,則會出現語法錯誤。 – jdf