K
K
Korol_Kotov2021-05-14 21:50:53
Python
Korol_Kotov, 2021-05-14 21:50:53

How to make leaderboard with db json discord.py?

I am trying to make top 10 coins in my bot. I don't know how it can be done, that's why I applied here, I didn't try to write anything, I just don't know how and what. So. My user's coins are money["user ID here"]["number of coins here"] . For those who don't get it:

{"676744847844897979": 0, "5465756846894984": 10}

And I need to output the top 10 from largest to smallest. Please help, I'm new to this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-05-14
@Korol_Kotov

d = {"676744847844897979": 0, "5465756846894984": 10}
print(sorted(d.items(), key=lambda item: item[1], reverse=True)[:10])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question