Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将元组的元组转换为列表的列表?_Python_List_Tuples - Fatal编程技术网

Python 如何将元组的元组转换为列表的列表?

Python 如何将元组的元组转换为列表的列表?,python,list,tuples,Python,List,Tuples,我想将元组中的元组转换为列表列表 我不想把它展平,不像,我也不想把它做成一个小数组 到目前为止,我唯一的想法是使用for循环迭代元组并复制值,但必须有更干净、更具python风格的东西。这就是您想要的吗- In [17]: a = ((1,2,3),(4,5,6),(7,8,9)) In [18]: b = [list(x) for x in a] In [19]: b Out[19]: [[1, 2, 3], [4, 5, 6], [7, 8, 9]] 这被称为列表理解,当您执行list

我想将元组中的元组转换为列表列表

我不想把它展平,不像,我也不想把它做成一个小数组


到目前为止,我唯一的想法是使用for循环迭代元组并复制值,但必须有更干净、更具python风格的东西。

这就是您想要的吗-

In [17]: a = ((1,2,3),(4,5,6),(7,8,9))

In [18]: b = [list(x) for x in a]

In [19]: b
Out[19]: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

这被称为列表理解,当您执行
list(x)
时,其中x是一个iterable(也包括元组),它会将其转换为相同元素的列表。

您可以尝试简单地映射(list,a)这在python解释器上起作用,但在脚本中不起作用…wierd。我在脚本中得到的错误是:TypeError:list()不带任何参数(给定1)您确定在脚本中没有类似-
def list()的函数:
?Anand S Kumar您刚刚解决了我的问题!太多了!。。。我在flask views.py中有另一个列表方法