Code Room
Code reviewHard
Question
Review this Python grouping that also tracks counts.
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.
Learn the concepts
from collections import defaultdict def group(records): groups = defaultdict(list) counts = defaultdict(int) for r in records: groups[r.key].append(r) # “defensive”: make sure the key exists in counts before incrementing counts.setdefault(r.key, 0) counts[r.key] = counts[r.key] + 1 return groups, countsRun or narrate your approach, then ask the coach.