F
F
fesano2022-03-30 17:25:25
Python
fesano, 2022-03-30 17:25:25

How can vkbottle bot display top 30 users from sqlite3?

I have many values, but they are used: nick, mess. So, I did the following to display the top:

tlist = db.execute('SELECT nick, mess FROM users ORDER BY mess DESC').fetchall()
for top in tlist:
  print(top)

Everything works fine, but the following is needed:
  • Output format (1. Daniil Yakush - 293)
  • Make top up to 30

I tried to make an output format, but I can't, the problem is that I don't understand how to work with tuples in a tuple. Also I do not understand how to make that the second user would be deduced. And so, an example of the top:
1. Daniil Yakush - 293
2. Dima Tselmer - 287
3. David Cherenkov - 286
4. Victoria Kovpak - 271
5. Artyom Volkov - 264
6. Vlad Karamov - 259
7. Nikita Chuprinin - 254
8. Alexandra Solnichenko - 231
9. Alexander Adamchik - 229
10. Rustem Zhumabek - 224
11. Albina Kan - 218
12. Dasha Savon - 213
13. Egor Olontsev - 212
14. Vasily Zhidkov - 211
15. Vitaly Zevsky - 203
16. Artur Sugrobov - 192
17. Aksinya Kurochkina - 187
18. Daniil Solnichenko - 185
19. Georgy Kovpak - 181
20. Yaroslav Solnichenko - 176
21. Victoria Solnichenko - 172
22. Artem Kun - 163
23. Igor Gritsyus - 158
24. Natalia Romanovskaya - 153
25. Sasha Solnichenko - 149
26. Artem Sverdlov - 144
27. Roman Troitsky - 142
28. Vitaly Chernyshev - 139
29. Misha Kuramshin - 132
30. Artyom Kuramshin - 127

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rPman, 2022-03-30
@rPman

use the keyword limit .. offset ..
be careful, if two records have the same mess, the sort order will not be defined for them (in this case, I can recommend double sorting by mess and then, for example, by id)

A
Alexander Nesterov, 2022-03-30
@AlexNest

1. Add to sqlLIMIT 30

I don't understand how to work with tuples in a tuple

Obviously, it's the same as with tuples outside of a tuple.
Do you really want to say that you did not find anything on the Internet, or that you were banned from Google?
Data structures in off-docs
And here, for example, [Learning Python. 5th ed. Volume 1. Mark Lutz]:
A separate chapter is devoted to tuples.
62446b8753009997782438.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question