# For the sake of example - assume that a hashing function is implemented based on the score
class Object
def __init__(self):
score = 0
def __repr__(self):
return f'<Object {self.score}>'
pairs = [(1, <Object 1>), (1, <Object 1>), (3, <Object 7>), (9, <Object 3>), (9, <Object 4>)]
filtered_pairs = [(1, <Object 1>), (3, <Object 7>), (9, <Object 4>)]
我知道我可以打电话
set
我知道我可以从itertools中进行groupby,并使用分数作为键实现排序,然后从每个组中获取最后一项,但我想知道是否有更有效的方法。