NDOJ/judge/utils/ranker.py

15 lines
311 B
Python
Raw Normal View History

2020-01-21 06:35:58 +00:00
from operator import attrgetter
2022-05-14 17:57:27 +00:00
def ranker(iterable, key=attrgetter("points"), rank=0):
2020-01-21 06:35:58 +00:00
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)