+ 1
using remove
list=["a","b","c","a"] list.remove("a") this removes only the first a, I want to remove both. How ?
3 Respostas
+ 3
You could do:
for i, letter in enumerate(list) :
if letter=='a':
del list[i]
+ 3
list = [x for x in list if x!="a"]
By the way it is very bad to call your variable 'list' because you override the builtin function. Use my_list or whatever else you want.
0
Good question