NDOJ/judge/utils/ranker.py
2021-05-24 15:18:39 -05:00

15 lines
312 B
Python

from operator import attrgetter
def ranker(iterable, key=attrgetter('points'), rank=0):
delta = 1
last = None
for item in iterable:
new = key(item)
if new != last:
rank += delta
delta = 0
delta += 1
yield rank, item
last = key(item)