Dunder method to determine unique elements using set

Viewed 62

I have several objects in a list, like the following:

class Test(object):
    def __init__(self, ID, A, B, C, D, E):
        self.ID = ID
        self.A = A
        self.B = B
        self.C = C
        self.D = D
        self.E = E


test1 = Test(6124, 6, 'Tim', 'Football', 'Soccer', 'USA')
test2 = Test(6124, 7, 'Joe', 'Basketball', 'Soccer', 'USA')
test_list = [test1, test2]

I want to do set(test_list) and have it determine unique values based on the ID attribute.

Is there a dunder method that I can use in the class to determine unique values?

Thanks, Jack

0 Answers
Related