Why this list not removing 3 after 2? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
1 Answer
0
l=[1,2,3,4,5,3,2,1 ] l.sort() print(l) for i in l[:]: # < do this. print (i) while i in l: l.remove(i) print (l) When ever you modify the length of an iterable, (in this case..."remove") you should loop over a copy of it. Although...I'm not sure what your trying to do.
8th May 2020, 11:31 PM
rodwynnejones
rodwynnejones - avatar