Python check if object is in list of objects
- by John
Hi,
I have a list of objects in Python. I then have another list of objects. I want to go through the first list and see if any items appear in the second list.
I thought I could simply do
for item1 in list1:
for item2 in list2:
if item1 == item2:
print "item %s in both lists"
However this does not seem to work. Although if I do:
if item1.title == item2.title:
it works okay. I have more attributes than this though so don't really want to do 1 big if statement comparing all the attributes if I don't have to.
Can anyone give me help or advise on what I can do to find the objects which appear in both lists.
Thanks