![]() |
Deleting from a list of objects - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Deleting from a list of objects (/thread-13941.html) |
Deleting from a list of objects - buddih09 - Nov-07-2018 Dear all, I want to create series of objects belonging a class and keep all these objects in a list (say a population of people). I thought of maintaining the list because I need to iterate through the objects many times and match some of their attributes (search based on age or something else). But then I realized that when I want to delete one of those objects (a person dies or opts out), just removing it from the list is not enough because even after that an instance of the object seem to exist outside the list. So I have to both remove it from the list and delete the instance that exists outside. Is there a better way to do this? Thank you RE: Deleting from a list of objects - Larz60+ - Nov-07-2018
RE: Deleting from a list of objects - ichabod801 - Nov-07-2018 Why does it matter if it exists outside the list? If the list is the live ones, you can iterate through that and only deal with the live ones. |