Nov-22-2020, 01:07 AM
list
is already an object in python. It is recommended you use another name for your function.It is a bad idea to remove objects from an object while you're iterating over it. It will mess with the iteration. You're doing this in lines 5-8.
An alternative is to make a copy without the objects you want removed, or to remove them outside of an iteration.
Remove by copy elements that don't match
a = [item for item in a if item != c]Remove without iteration
while c in a: a.remove(c)Remove while iterating over a copy
for i in list(a): if i == c: a.remove(i)