0

I discussed this with my friends, I am a high school student, I am not able to understand why '2' is not removed and why the first and last elements are.

 n = [1, 2, 5, 8, 57, 3]
 for i in n:
     if i < 5:
        n.remove(i)
 print(n)

Output:

[2, 5, 8, 57]
mkrieger1
  • 14,486
  • 4
  • 43
  • 54

0 Answers0