Which fix removes the bug?
scores = ['9', '10', '100'] print(max(scores)) # expected 100
- Compare with
key=int - Use
sorted(scores)[-1] - Call
max(*scores)here - Use
scores.max()instead
Strings compare character by character, so '9' beats '100'; key=int compares them as numbers.
Play Problem Solving ▸