Code Room
Code reviewMediumcr-g275
Subject Comparator violationsLevel Mid–Senior~16 minCommon in Code quality & review interviewsIndustries Software development

Question

Review this Python code that keeps the top-N items by score using a heap.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewpython
import heapq class Item:    def __init__(self, score, payload):        self.score = score        self.payload = payload def top_n(items, n):    heap = []    for it in items:        heapq.heappush(heap, (it.score, it))        if len(heap) > n:            heapq.heappop(heap)    return [pair[1] for pair in heap]
Run or narrate your approach, then ask the coach.