0

I am new to python and I'm trying to do a exercise, a part of it I had to remove certain elements which are bigger than 2 but there is a problem with 'four'. I don't understand why the code doesn't remove 'four' again after it does once. this problem only happens with 'four' as I noticed. Here's the code I hope you can help me:

a = input().split()
a = [int(i) for i in a]
for i in a:
    if i > 2:
        a.remove(i)
print(a)
ahmadre147
  • 15
  • 5
  • Please and input example and the expecting output – azro Oct 10 '20 at 09:17
  • 4
    Does this answer your question? [How to remove items from a list while iterating?](https://stackoverflow.com/questions/1207406/how-to-remove-items-from-a-list-while-iterating) – Wups Oct 10 '20 at 09:17
  • 1
    The problem is that you remove an element bu you continu iterating, so you jumped a bo – azro Oct 10 '20 at 09:18

0 Answers0