【Python学习】如何删除二维列表中某些特定列值的行?

例如,如果我们有二维列表:

list1 = [['tom',67,'engineer',2], ['ron',42,'scientist',4], ['alie',56,'doctor',3], ['rambo',29,'lawyer',7]]

使用remove()方法

for value in list1[:]:
if value[3] % 2 != 0:
list1.remove(value)

结果

[['tom', 67, 'engineer', 2], ['ron', 42, 'scientist', 4]]

posted @ 2021-11-25 20:30  易点灵通  阅读(814)  评论(0)    收藏  举报