using remove | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

using remove

list=["a","b","c","a"] list.remove("a") this removes only the first a, I want to remove both. How ?

13th Feb 2020, 6:11 PM
Rakshya Thapa
3 ответов
+ 3
You could do: for i, letter in enumerate(list) : if letter=='a': del list[i]
13th Feb 2020, 6:31 PM
HonFu
HonFu - avatar
+ 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.
13th Feb 2020, 7:26 PM
Tibor Santa
Tibor Santa - avatar
0
Good question
13th Feb 2020, 6:33 PM
Wasi
Wasi - avatar