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.
Since they're not hashable, you can't use a set directly. The titles should be though.
Here's the first part.
You're going to need to describe what database/ORM etc. you're using for the second part though.