Skip to content
How do I create a leaderboard in python?
Profile icon
DarshanRajpara1

I am trying to create a leaderboard for python and cannot figure it out. I want the leaderboard to be sortable and in this format:

Score | Name

Can anyone help me?

You are viewing a single comment. View All
Profile icon
Coder100

Hello. You can sort an array, then map the array, and finally join the array.

The code is going to be something like this:

users = [("username", 5), ("someone", 15), ('n00b', 0)] # Sort user array users.sort(key=lambda a: a[1], reverse=True) # Format the users leaderboard = map(lambda user: user[0] + "| " + str(user[1]), users) # Output print("\n".join(leaderboard))

Hopes this helps!

Profile icon
DarshanRajpara1

@Coder100
Thank you!

Profile icon
Coder100

no problem! Happy to help!

@DarshanRajpara1

Profile icon
DarshanRajpara1

@Coder100
Just one question:
What if I wanted it to save it to a file?

Profile icon
Coder100

you can use file i/o lemme find it for ya

@DarshanRajpara1