list = ['02', '03', '04', '05', '06', 'Inactive', 'Inactive', 'Inactive', 'Inactive', 'Inactive']
list.remove('Inactive')
print list
Run Code Online (Sandbox Code Playgroud)
但它只是保持结果不变.我错过了什么?
它移除第一次出现Inactive的列表的文档remove的方法说.要删除所有匹配项,请使用loop/method/lambda/LC.例如:
myList = ['02', '03', '04', '05', '06', 'Inactive', 'Inactive', 'Inactive', 'Inactive', 'Inactive']
removedList = [x for x in myList if x!='Inactive'] # original list unchanged
# or
removedList = filter(lambda x: x!='Inactive', myList) #leaves original list intact
Run Code Online (Sandbox Code Playgroud)
顺便说一句,不要list用作变量名
| 归档时间: |
|
| 查看次数: |
43 次 |
| 最近记录: |