+ 3
Please who can explain why this doesn't remove every item in the list.
List = [i for i in range(8)] for i in List: List.remove(i) Print(List)
3 Respuestas
+ 6
when you remove, list size is gets decreased so the next value is, not what you expected value as of without remove.
See ex: list is [2,3,4] then if you remove 2, (its at index 0) , then list is [3,4 ] and next value is at index 1 is 4. Not 3
hope it helps.
+ 4
Jayakrishna🇮🇳 thank you so much. I understand it now.
+ 4
List.remove(List[0])
this is a 2nd alternative to Lothar s solution.
while list:
list.pop(0)