+ 1

I want to remove the zeroes from the list

I want to remove zeroes from this list and basically this is what I’ve got so far. And then and error comes saying list is out of index range. HELP https://code.sololearn.com/ctrFvrRgz1lW/?ref=app

23rd Apr 2018, 4:28 AM
Andrews Essilfie
7 Respuestas
+ 5
https://code.sololearn.com/crpXpC2LUcIx/?ref=app X = [0,5,0,0,3,1,15,0,12] X = [e for e in X if e != 0] print(X)
23rd Apr 2018, 4:34 AM
Emma
+ 3
I love what Xan did! One liners rock!!! But if you wanted to print what you get after each iteration, here is what I have got with the while loop https://code.sololearn.com/c1Zp8dusnHP0/?ref=app
23rd Apr 2018, 4:37 AM
cyk
cyk - avatar
+ 3
cyk Good suggestions also ☺ My code is not readable by a novice. Ok though, if lots of comments above it explaining. Another reminder how important comments are!
23rd Apr 2018, 4:40 AM
Emma
+ 2
Use while because it gets the length of the original list and that is the range it is working with. But as you delete elements the list gets shorter. So at some point value is out of range for the new list
23rd Apr 2018, 4:33 AM
cyk
cyk - avatar
+ 2
@Xan yeah. I try to put comments everytime. Thanks
23rd Apr 2018, 5:41 AM
Andrews Essilfie
+ 1
Thanks so much everybody. Am new beginner. And I have an exam on this stuff like this Tuesday so I really appreciate the help. Very much thanks.
23rd Apr 2018, 5:38 AM
Andrews Essilfie
+ 1
@cyk I understand now. Thanks
23rd Apr 2018, 5:39 AM
Andrews Essilfie