Python Forum
Deleting from a list of objects
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Deleting from a list of objects
#1
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
Reply
#2
  • we cannot properly answer unless you post code.
  • Looks like you really need a dictionary, not a list
Reply
#3
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating list of lists, with objects from lists sgrinderud 7 1,611 Oct-01-2022, 07:15 PM
Last Post: Skaperen
Question Keyword to build list from list of objects? pfdjhfuys 3 1,555 Aug-06-2022, 11:39 PM
Last Post: Pedroski55
  How to store the resulting Doc objects into a list named A xinyulon 1 1,893 Mar-08-2022, 11:49 PM
Last Post: bowlofred
  Grouping and sum of a list of objects Otbredbaron 1 3,194 Oct-23-2021, 01:42 PM
Last Post: Gribouillis
  deleting select items from a list Skaperen 13 4,470 Oct-11-2021, 01:02 AM
Last Post: Skaperen
  Deleting employee from list SephMon 3 3,243 Jan-05-2021, 04:15 AM
Last Post: deanhystad
  Passing List of Objects in Command Line Python usman 7 3,153 Sep-27-2020, 03:45 PM
Last Post: ndc85430
  How to create and define in one line a 2D list of class objects in Python T2ioTD 1 2,029 Aug-14-2020, 12:37 PM
Last Post: Yoriz
  Organizing list of objects by attribute scarney1988 3 2,214 Mar-11-2020, 03:55 PM
Last Post: scarney1988
  List of objects with sublist medatib531 4 2,311 Mar-01-2020, 06:16 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020