Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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
Python3将元素添加到每个列表中_Python_List_Append_Add_Extend - Fatal编程技术网

Python3将元素添加到每个列表中

Python3将元素添加到每个列表中,python,list,append,add,extend,Python,List,Append,Add,Extend,我正在逐行遍历excell工作表,并读取要列出的单元格值。对于每一行数据,我需要在末尾添加从sheet name中提取的另外两个内容,它们存储在列表DI_DJ=[el1,el2] 我的代码如下所示: data_rows.append([cell.value for cell in row]) data_rows.extend(DI_DJ) 它以输出列表的形式给出,其结构如下: [[value,of,cells,in,row],el1,el2] 我想得到的是: [[value,of,cells,

我正在逐行遍历excell工作表,并读取要列出的单元格值。对于每一行数据,我需要在末尾添加从sheet name中提取的另外两个内容,它们存储在列表DI_DJ=[el1,el2]

我的代码如下所示:

data_rows.append([cell.value for cell in row])
data_rows.extend(DI_DJ)
它以输出列表的形式给出,其结构如下:

[[value,of,cells,in,row],el1,el2]

我想得到的是:

[[value,of,cells,in,row,el1,el2]]

我一直在寻找答案,试过了

数据行+=DI_DJ


但是我总是得到同样的结果。

你能把列表理解结果和列表DI_DJ相加吗

data_rows.append([cell.value for cell in row] + DI_DJ)

你能把列表理解结果和列表DI_DJ相加吗

data_rows.append([cell.value for cell in row] + DI_DJ)

谢谢你,很有魅力:)抱歉打扰了,这里的新手。不用担心!谢谢你在你的问题中发布了所有的细节/例子。谢谢,就像魅力:)很抱歉打扰你,这里的新手。不用担心!感谢您发布问题中的所有详细信息/示例。