OneBug This week's bugs
Spot the bug Python
1
# Build the leaderboard: each team's average score, in whole points.
2
scores = {"red": [2, 3], "blue": [3, 4], "green": [4, 5]}
3
board = {}
4
for team, pts in scores.items():
5
    avg = sum(pts) / len(pts)
6
    board[team] = round(avg)
7
ranked = dict(sorted(board.items(), key=lambda kv: -kv[1]))
8
print(ranked)
9
# expected: {'green': 5, 'blue': 4, 'red': 3}
10
# actual:   {'blue': 4, 'green': 4, 'red': 2}  (!)

Read the full write-up for this bug (spoilers)