how does the method .remove make difference in python?

  list, python-3.x
a = [(1, 1), (35, 1), (1, 35), (35,35)]

for i in a:
    print(i)

then it prints

(1, 1)
(35, 1)
(1, 35)
(35, 35)

however this code , though I expected the same result

a = [(1, 1), (35, 1), (1, 35), (35,35)]

for i in a:
   a.remove(i)
   print(i)

then the result is

(1, 1)
(1, 35)

How can the method .remove make this difference? I have no idea how it works. Please help me!

Source: Python-3x Questions

LEAVE A COMMENT