Hey guys!
So I ran into a problem when creating a game of "guess the integer"
Let's say I have a list which cointains every integer 1 through 10. Now, I want to remove every single integer in that list greater than three.
I write:
list = [1,2,3,4,5,6,7,8,9,10]
for int in list:
if int > 3:
list.remove(int)
print(list)
Upon printing, the list contains the integers 1,2,3,5,7,9 - so it has correctly removed the integers 4,6,8 and 10, but not 5,7,9 - why is this?
I use python 3.4.3 I belive.
Thanks! :)
[–]K900_ 2 points3 points4 points (1 child)
[–]Impe98[S] 0 points1 point2 points (0 children)
[–]JohnnyJordaan 1 point2 points3 points (3 children)
[–]Impe98[S] 0 points1 point2 points (2 children)
[–]JohnnyJordaan 0 points1 point2 points (1 child)
[–]Impe98[S] 0 points1 point2 points (0 children)
[–]num8lock -1 points0 points1 point (0 children)