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
2 ответов
+ 1
Let text be the list variable
Iterate over the list
Check if element == 'r'
▪ text.remove('r')
+ 1
mylist = ['r', 'b', 'r', 'i', 'r', 'n', 'g', 'r', 'o', '!']
while 'r' in mylist:
mylist.remove('r')
print(*mylist, sep='')