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

I want to get the name that is in the 1st place in a list

I can’t find a specific solution to my problem so I’m opening this question. I have a list,

diamonds = [40, 21, 8, 4, 25]
names = ['The maze', 'Plane', 'skin', 'tp', 'hemlet']
s = sorted(zip(diamonds, names), reverse=True)[:3]
print(s)

but I would like to get the name that is in the 0, 1 and 2 place. On the net I find that the reverse, get the place from a name. Is there a solution to my problem?

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

>Solution :

If you just want the names, then you can just pick the name from the tuples you created:

s =[item[1] for item in sorted(zip(diamonds, names), reverse=True)[:3]]

I get the output:

['The maze', 'hemlet', 'Plane']
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