使用for循环打印列表中的数字无法正确打印

时间:2019-12-29 18:09:36

标签: python python-3.x

我希望将0和7以外的数字打印在列表中而不创建新列表,但是输出错误。

def spy_game(nums):
    for e in nums:
        if not(e==0 or e==7):
            nums.remove(e)
        else:
            pass
    print(nums)


spy_game([1,2,4,0,0,7,5,2,3])

输出-

[2, 0, 0, 7, 2]

但是我想要

[0, 0, 7]

0 个答案:

没有答案