How I Built a Simple Leaderboard System (and Finally Understood Sorting Properly)
When I first heard "leaderboard system", I thought it would be complicated.
But after trying it myself, I realized it’s just about organizing data clearly.
'
Problem
I wanted to:
Store user performance
Show leaderboard
Sort based on difficulty and attempts
** Code (Python)**
Python
class Solution:
def leaderboardSystem(self):
leaderboard = [
{"name": "Asha", "score": 95, "difficulty": "Hard", "attempts": 2},
{"name": "Ravi", "score": 80, "difficulty": "Medium", "attempts": 3},
{"name": "John", "score": 70, "difficulty": "Easy", "attempts": 1},
{"name": "Meena", "score": 85, "difficulty": "Hard", "attempts": 4}
]
difficulty_order = {
"Easy": 1,
"Medium": 2,
"Hard": 3
}
sorted_data = sorted(
leaderboard,
key=lambda x: difficulty_order[x["difficulty"]]
)
print("\n🏆 Leaderboard\n")
print("Name Score Difficulty Attempts")
print("--------------------------------------")
for user in sorted_data:
print(f'{user["name"]:<8} {user["score"]:<7} {user["difficulty"]:<11} {user["attempts"]}')
**Leaderboard
Name Score Difficulty Attempts
John 70 Easy 1
Ravi 80 Medium 3
Asha 95 Hard 2
Meena 85 Hard 4**
Extra: Sorting by Attempts
Leaderboard (Sorted by Attempts)
Name Score Difficulty Attempts
John 70 Easy 1
Asha 95 Hard 2
Ravi 80 Medium 3
Meena 85 Hard 4
What I Learned
Sorting is powerful when combined with logic
Data representation matters more than complexity
Even big systems start simple
Final Thought
A leaderboard looks complex…
But in reality, it’s just:
structured data + smart sorting
Top comments (0)