为了能到远方,脚下的每一步都不能少.|

园龄:粉丝:关注:

2021-12-16 00:20阅读: 100评论: 0推荐: 0

python 遍历列表时删除元素

testObjs = ["1","2","3","1"]
# i=0
# for o in testObjs:
#     testObjs.pop(i)
#     print(o)
#     i+=1
j=0
length = len(testObjs)
for i in range(0,length):
    o = testObjs[i-j]
    if(o=="1"):
        testObjs.pop(i-j)
        j+=1

print(testObjs)

结果

本文作者:乘舟凉

本文链接:https://www.cnblogs.com/czlnb/p/15696117.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   乘舟凉  阅读(100)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起