Wanted to get the difference between two list where list1 is
l1 = range(10003, 10011)
And list2 i.e list of database object is`
l2 = [<Model_obj: 10003 (3)>, <Model_obj: 10005 (5)>, <Model_obj: 10006 (6)>, <Model_obj: 10007 (7)>, <Model_obj: 10008 (8)>, <Model_obj: 10009 (9)>, <Model_obj: 10011 (11)>]
where <Model_obj: 10003 (3)> is having attributes like number, name, id etc. And 10003, 10005,... 10011 represents the values of number field of the model.
Now I want to get the list of values of missing numbers of second list i.e list1 while comparing with first list i.e list1
so in this case The Answer would be [10004, 10010] because this two number is missing in list2
I can able to do this while creating a number list of list2 using for loop and taking help of Get difference between two lists
I can achieve this by creating list3 as
l3 = set([obj.number for obj in l2])
response = set(l1) - l3
**Output**
{10004, 10010}
But is this a pythonic way to do this job?