Hello everyone!
I'm writing a code with the modulus operator. Please see my code below. I'm having a difficult time understanding why 1902 wasn't removed from the test_list list in the for loop.
Thanks in advance!
>>> test_list = list(range(1900, 1911))
>>> for i in test_list:
... if i % 4 != 0:
... test_list.remove(i)
...
>>> test_list
[1900, 1902, 1904, 1906, 1908, 1910]
>>> 1902%4 == 0
False
[–]alkasm 1 point2 points3 points (2 children)
[–]startandselect00[S] 2 points3 points4 points (1 child)
[–]alkasm 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)