P
P
pivazik2020-06-20 06:20:38
Python
pivazik, 2020-06-20 06:20:38

How to make a python ranking table?

Hello, how can I implement a rating table?
Let's say I have a dictionary that stores user data: I need to display the keys and their values ​​​​from this table and do something like this table: 1) 2 - 23 2) 5 - 19 3) 4 - 17
top_list = {1: 14, 2: 23, 3: 5, 4: 17, 5: 19}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-06-20
@pivazik

for i, (k, v) in enumerate(sorted(top_list.items(), key=lambda n: n[1], reverse=True), 1):
  print(f'{i}) {k} - {v}')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question