Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.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 - Fatal编程技术网

Python中的列表-不同行中的每个数组

Python中的列表-不同行中的每个数组,python,list,Python,List,如何使用以下格式创建新列表 每行中的3个数组应位于不同的行中 a= [['111,0.0,1', '111,1.27,2', '111,3.47,3'], ['222,0.0,1', '222,1.27,2', '222,3.47,3'], ['33,0.0,1', '33,1.27,2', '33,3.47,3'], ['44,0.0,1', '44,1.27,2', '4,3.47,3'], ['55,0.0,1', '55,1.27,2', '55,3.47

如何使用以下格式创建新列表

每行中的3个数组应位于不同的行中

a= [['111,0.0,1', '111,1.27,2', '111,3.47,3'],
    ['222,0.0,1', '222,1.27,2', '222,3.47,3'],
    ['33,0.0,1', '33,1.27,2', '33,3.47,3'],
    ['44,0.0,1', '44,1.27,2', '4,3.47,3'],
    ['55,0.0,1', '55,1.27,2', '55,3.47,3']]
最终所需输出:

 b=[['111,0.0,1', 
  '111,1.27,2', 
  '111,3.47,3',
  '222,0.0,1', 
  '222,1.27,2', 
  '222,3.47,3',
  '33,0.0,1', 
  '33,1.27,2', 
  '33,3.47,3',
  '44,0.0,1',
  '44,1.27,2',
  '44,3.47,3',
  '55,0.0,1', 
  '55,1.27,2', 
  '55,3.47,3']]

这就是你要找的吗

b = [[j for i in a for j in i]]

需要明确的是,Python中没有行与列的概念。您的最终结果只是另一个列表中的一大串
str

您可以通过将所有原始小列表链接在一起来创建大列表(
a[0]+a[1]+…
),我们可以使用它

import itertools
big_list = list(itertools.chain(*a))
要将其放入另一个列表中

b = [big_list]

哦,是的!这正是我想要的。谢谢