Python 利用集合确定唯一元素的Dunder方法
列表中有几个对象,如下所示:Python 利用集合确定唯一元素的Dunder方法,python,python-3.x,oop,set,Python,Python 3.x,Oop,Set,列表中有几个对象,如下所示: 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', 'US
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]
我想做set(test_list)并让它根据ID属性确定唯一值
我可以在类中使用dunder方法来确定唯一值吗
谢谢,
杰克