OOP python - removing class instance from a list

You could have stored them in a dict and removed them by name

di = {"test" : my_instance()}
del di['test']

You could use a list comprehension:

thelist = [item for item in thelist if item.attribute != somevalue]

This will remove all items with item.attribute == somevalue.

If you wish to remove just one such item, then use WolframH's solution.


Iterate through the list, find the object and its position, then delete it:

for i, o in enumerate(obj_list):
    if o.attr == known_value:
        del obj_list[i]
        break