小编ale*_*nes的帖子

使用另一个列表的某些值附加列表

我有一份清单清单mainList.我希望附上一个subList,但只有第2,第3,第4,第5和第7项.

for subList in file:
    mainList.append(subList[#items 2,3,4,5,7])
Run Code Online (Sandbox Code Playgroud)

除此之外还有办法吗?

for subList in file:
    temp = []
    for item in subList[1:]:
        if #item not the 6th item:
            temp.append(item)
    mainList.append(temp)
Run Code Online (Sandbox Code Playgroud)

我可以在没有temp列表的情况下执行此操作,并且嵌套的for循环附加此列表吗?

python list append

2
推荐指数
1
解决办法
44
查看次数

标签 统计

append ×1

list ×1

python ×1