[At Coder] ABC128B --Guidebook

This is a problem to study ** sort **.

Since the city name and points are stored, is it a dictionary? → Since there are multiple cities in the same city, the dictionary cannot be used.

Is the restaurant number an index on the list? → It will be sorted, so it is better to put the restaurant number in the list.

That's why I will put the number, city name, and score in the list.

How do you sort the city names and points? →l.sort(key=lambda x:x[1],x[2])

Kimo is a place where ** city names are in dictionary order (ascending order), but scores are in descending order **.

The commentary said, ** Multiply the score by -1 **, so I thought it was true.

If you want the 1st key to be in ascending order and the 2nd key in descending order I found an article that says ** If you add-to the key, it will be in descending order ** I tried using that method.

Sort by multiple keys

n=int(input())
l=[]

for i in range(n):
    s,p=input().split()
    l.append([i+1,s,int(p)])

l.sort(key=lambda x:(x[1],-x[2]))

for i in l:
    print(i[0])

Recommended Posts

[At Coder] ABC128B --Guidebook
At Coder (2020/09/08)
Fill at Coder
At Coder # 1 at midnight
[Python] ABC133B (upper right triangle problem) [At Coder]
[At Coder] Acing C-XYZ Triplets
[Python] Competitive template [At Coder]
[At Coder] ABC085C --Otoshidama's Python answer