2016-11-10 152 views
-2

我想使用Python將列表的列表轉換爲元組列表。但是我想在不重複嵌套列表的情況下這樣做,因爲它會增加腳本的執行時間。有什麼方法可以鍛鍊我嗎?Python將列表的列表轉換爲元組列表

由於提前

+2

您可以避免使用[列表解析]寫一個顯式循環(https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions)或['map'函數](https://docs.python.org/2/library/functions.html#map),但它仍然會遍歷所有數據。 – khelwood

回答

0
converted_list = [tuple(i) for i in nested_list]