-1

So i want to delete all 3s from numbers

numbers = [3, 3, 3, 3, 3, 1, 2, 2, 3, 3, 3, 3, 3, 3]
for i in numbers:
    if i == 3:
        numbers.remove(3)
print(numbers)

It feels like this should do it but it prints

[1, 2, 2, 3, 3, 3, 3, 3]

as the result.. It seems like consecutive 3s are the problem but I don't know why..

1 Answers1

0
result = [i for i in numbers if i != 3]
Sachin Kohli
  • 1,956
  • 1
  • 1
  • 6