Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to print a list value one below another

I need to sort a ranking of points by descending order. The users and points are inside lista_ranking which includes de following code:

[{‘partido’: {‘codigo’: ‘AAA’, ‘fecha’: datetime.date(2022, 11, 20), ‘hora’: ’13:00hs’, ‘equipo_local’: ‘Catar’, ‘equipo_visitante’: ‘Ecuador’, ‘estado’: ‘Finalizado’, ‘goles_local’: 0, ‘goles_visitante’: 1}, ‘usuario’: {‘cedula’: ‘123’, ‘nombre’: ‘Gon’, ‘apellido’: ‘Henderson’, ‘fecha’: ‘(2003, 3, 12)’, ‘puntaje’: 5}, ‘goles_local’: 1, ‘goles_visitante’: 0}, {‘partido’: {‘codigo’: ‘AAA’, ‘fecha’: datetime.date(2022, 11, 20), ‘hora’: ’13:00hs’, ‘equipo_local’: ‘Catar’, ‘equipo_visitante’: ‘Ecuador’, ‘estado’: ‘Finalizado’, ‘goles_local’: 0, ‘goles_visitante’: 1}, ‘usuario’: {‘cedula’: ‘1234’, ‘nombre’: ‘George’, ‘apellido’: ‘Stev’, ‘fecha’: ‘(2003, 3, 12)’, ‘puntaje’: 8}, ‘goles_local’: 0, ‘goles_visitante’: 1}]

With the code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ranking_high_to_low=sorted([(numeros['usuario']['puntaje'], numeros['usuario']['nombre'], numeros['usuario']['apellido']) for numeros in lista_ranking], reverse=True) print(ranking_high_to_low)

It prints the ranking from highest to lowest like this:

[(8, 'George', 'Stev'), (5, 'Gon', 'Henderson')]

Which for should I use in order for it to print the ranking as follows:

George Stev 8
Gon Henderson 5

>Solution :

I think that this should do the trick:

   for (num, first, last) in ranking_high_to_low:
       print("{} {} {}".format(first, last, num))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading