When i try for loop to remove all a's from list here is my code:
list5 = ["a","b","a","b","a","b","c"]
def remove_values_from_list(_list, val):
for val in _list:
_list.remove(val)
remove_values_from_list(list5, "a")
print(list5)
it return's:
["b","b","b"]
and when i use while instead of for it returns:
list5 = ["a","b","a","b","a","b","c"]
def remove_values_from_list(_list, val):
while val in _list:
_list.remove(val)
remove_values_from_list(list5, "a")
print(list5)
["b","b","b","c"]
Can someone explain me why does for loop doesn't return last c?