+ 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
7 Answers
+ 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)
+ 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
+ 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!
+ 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
+ 2
@Xan yeah. I try to put comments everytime. Thanks
+ 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.
+ 1
@cyk I understand now. Thanks