0
list.remove(obj)
if there are many same type objects in the list which 1 will it remove?
4 Answers
+ 5
Which programming language?
+ 3
# It will remove the first one.
# The code below will return [ 'b', 'c', 'a' ]
L = [ 'a', 'b', 'c', 'a' ]
L.remove('a')
print(L)
# If you want to remove ALL instances of an element, see the code-example below.
# It will return [ 1, 2, 4, 5 ]
L = [ 1, 2, 4, 3, 3, 5, 3 ]
L = list(filter(lambda x : x != 3, L))
print(L)
+ 1
py
0
is it possible to remove all same type objects with remove? without any additional logic