Issue
I have 2 lists of objects:
For example:
class Object1:
def __init__(self, id):
self.id = id
Object1List = []
Object1List.append(Object1("id", 1))
Object1List.append(Object1("id", 2))
Object1List.append(Object1("id", 3))
class Object2:
def __init__(self, id):
self.id = id
Object2List = []
Object2List.append(Object2("id", 3))
Object2List.append(Object2("id", 4))
Object2List.append(Object2("id", 5))
Object2List.append(Object2("id", 6))
How do I remove any objects from Object1List
with the same id
as one in Object2List
?
Solution
Create a function with like:
def remove_replicates(list1, list2):
temp = list1
for obj1 in list1:
for obj2 in list2:
if obj1.id == obj2.id:
temp.remove(obj1)
continue
return temp
Answered By - BarisSayit
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.