发布时间:2019-07-14 10:04:39编辑:auto阅读(1882)
总结:
for循环内部index(指针)每次循环自增1,删除的元素的索引会上移
lst = ['大鹏展翅','天道酬勤','前程似锦']
for el in lst:
if el in ['天道酬勤','前程似锦']:
lst.remove(el)
print(lst)
错误结果:
['大鹏展翅', '前程似锦']
lst = ['大鹏展翅','天道酬勤','前程似锦']
del_lst =[]
for el in lst:
if el in ['天道酬勤','前程似锦']:
del_lst.append(el)
for el in del_lst:
lst.remove(el)
print(lst)
正确结果:
['大鹏展翅']
上一篇: Python 异常处理
下一篇: 3G是什么?——让我们了解3G
49965
49223
39881
36922
31327
28163
27115
21917
21851
20191
127°
187°
174°
326°
350°
960°
1758°
1664°
1347°
2742°