[row+[myotherlist.pop(0)] if row[0]=='Download' else row for row in listScheduel]
例如:
list = [['Download',1,2,3],[0,1,2,3],['Download',1,2,3],['Download',1,2,3]]
otherlist = [0,1,2,3,4]
l = [ row+[otherlist.pop(0)] if row[0]=='Download' else row for row in list]
你的代码可读性很强,我不会更改它。你知道吗
通过列表理解,你可以写下如下内容:
您可以尝试一下,但要复制一份otherlist,以免丢失信息:
例如:
输出:
如果你真的想
append
,为什么不使用row.append(myOtherList[index])
?这样你就避免了IndexErrors
相关问题 更多 >
编程相关推荐