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

Time:02-25

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?

CodePudding user response:

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']
  • Related