I have a function for which I would like to go through a list of custom objects (with given midpoints) one at a time and take objects with unique midpoints and put them in a new list. The following code gives me an error that the list has no attribute called 'midPoint', but I am not sure how to get the code to search the list for objects with matching midpoints. Does anyone have recommendations?
class Obj():
def __init__(self, midPoint=[0,0]):
self.midPoint = midPoint
obj1 = Obj(midPoint = [1,1])
obj2 = Obj(midPoint = [2,2])
obj3 = Obj(midPoint = [3,3])
obj4 = Obj(midPoint = [1,1])
obj5 = Obj(midPoint = [2,2])
l = [obj1, obj2, obj3, obj4, obj5]
list_no_duplicates = []
def Delete_duplicates(list1):
for i in list1:
if i.midPoint not in list_no_duplicates.midPoint:
list_no_duplicates.append(x)
Delete_duplicates(l)
print list_no_duplicates