0

How to make a For loop to remove all specific elements in a list with remove() method

for example we have a list with more than one "r" element but as u all know remove() method takes just one argument so because of that I wanna use a For loop to iterate and deletes all "r" elements with in the list

4th Dec 2020, 3:14 PM
Dex
2 Antworten
+ 1
Let text be the list variable Iterate over the list Check if element == 'r' ▪ text.remove('r')
4th Dec 2020, 3:23 PM
Avinesh
Avinesh - avatar
+ 1
mylist = ['r', 'b', 'r', 'i', 'r', 'n', 'g', 'r', 'o', '!'] while 'r' in mylist: mylist.remove('r') print(*mylist, sep='')
4th Dec 2020, 6:53 PM
rodwynnejones
rodwynnejones - avatar