+ 1

Python - iterating and removing elements of lists

Hi, Why does this code omit the odd numbers when iterating i? my list = [i for i in range (8)] print (myList) for i in myList: print (i) myList.remove(i) print (myList) print (sum(myList)) Output: [0,1,2,3,4,5,6,7] 0 [1,2,3,4,5,6,7] 2 [1,3,4,5,6,7] 4 [1,3,5,6,7] 6 [1,3,5,7] 16

24th Jun 2019, 5:23 PM
Marek Kluczewski
Marek Kluczewski - avatar
0 odpowiedzi