Python Forum
How to check if class instance exists in a list of class instance objects?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to check if class instance exists in a list of class instance objects?
#1
Hi,

I have a list of class instances:

mylist = [ myClass(name=n1), myClass(name=n2), myClass(name=n1), myClass(name=n3) ]
How can I get rid of duplicates in this list?
I know that the two instances with the name='n1' are in reality 2 different objects, so they are in reality not duplicates.
But for my project, having several instances with the same parameters means basically duplicates and I need to clean up the list accordingly.

Is there any easy way to do it?

Thanks.
Reply


Messages In This Thread
How to check if class instance exists in a list of class instance objects? - by sonicblind - May-25-2018, 10:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Copying methods to effect the new owner instead of the old instance Daniel285 2 233 Jun-03-2024, 07:58 AM
Last Post: Gribouillis
  [split] Class and methods ebn852_pan 15 870 May-23-2024, 11:57 PM
Last Post: ebn852_pan
  [SOLVED] [listbox] Feed it with dict passed to class? Winfried 3 349 May-13-2024, 05:57 AM
Last Post: Larz60+
  Class and methods Saida2024 2 326 May-13-2024, 04:04 AM
Last Post: deanhystad
  How does this code create a class? Pedroski55 6 692 Apr-21-2024, 06:15 AM
Last Post: Gribouillis
  class definition and problem with a method HerrAyas 2 394 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  Printing out incidence values for Class Object SquderDragon 3 452 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  class and runtime akbarza 4 508 Mar-16-2024, 01:32 PM
Last Post: deanhystad
  Help with to check an Input list data with a data read from an external source sacharyya 3 601 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  Operation result class SirDonkey 6 702 Feb-25-2024, 10:53 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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