I've got a list of objects and I've got a db table full of records. My list of objects has a title attribute and I want to remove any objects with duplicate titles from the list (leaving the original).
Then I want to check if my list of objects has any duplicates of any records in the database and if so, remove those items from list before adding them to the database.
I have seen solutions for removing duplicates from a list like this: myList = list(set(myList)), but i'm not sure how to do that with a list of objects?
I need to maintain the order of my list of objects too. I was also thinking maybe I could use difflib to check for differences in the titles.
解决方案
The set(list_of_objects) will only remove the duplicates if you know what a duplicate is, that is, you'll need to define a uniqueness of an object.
In order to do that, you&#