Say I have a model object ‘Person’ defined, which has a field called ‘Name’. And I have a list of people:
l = ['Bob','Dave','Jane']
I would like to return a list of all Person records where the first name is not in the list of names defined in l.
What is the most pythonic way of doing this?
EDIT: After thinking about it, what I really was trying to do is come up with a sub list of l that wasn’t present in the Person table. Is there an efficient way of doing this? I can think of a few ways, not sure how efficient though.
Renaming
lfor readability:UPDATE 1: Answer to the second question (in your ‘EDIT’ paragraph):
Yes, the “right hand side” of difference (but not ‘-‘) accepts any iterable (I had to look it up to confirm).