html tool

2020年8月19日星期三

python 数组在for中的i 不是一定从0- len的

 问题记录:

在配置中一个数组一直del有问题,方式如下:

index =0 

for i in arr:

    if i["tt"] == ..:

      del arr[index]

   index = index +1


解答:

       debug后发现 这里的i不是从0 ~ len(arr),是有从len(arr)~0,也有0~len(),只有2个元素,是否有其他没测试

       还是老实的用index = arr.index(i) ,del arr[index]

参考: https://www.runoob.com/python/python-lists.html


没有评论:

发表评论