简体   繁体   English

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

[英]Python3 add element to every list of lists

I'm iterating through excell sheet row by row and read cell values to list. 我逐行遍历excell工作表并读取要列出的单元格值。 For every row of data I need to add to the end two more things extracted from sheet name, which are being stored in list DI_DJ = [el1, el2] 对于数据的每一行,我都需要从工作表名称中提取另外两件事,它们存储在列表中DI_DJ = [el1,el2]

My code look like this: 我的代码如下所示:

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

and it gives as output list which has structure like: 它给出了具有如下结构的输出列表:

[[value, of, cells, in, row], el1, el2] [[值,单元格,在行中的值,el1,el2]

what I'm trying to get is: 我想要得到的是:

[[value, of, cells, in, row, el1, el2]] [[值,单元格,在行中,el1,el2]

I've looked for answer, tried 我一直在寻找答案,尝试过

data_rows += DI_DJ data_rows + = DI_DJ

but I always ended up with same result. 但我总是以相同的结果告终。

您可以将列表理解结果与列表DI_DJ相加吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM