Today's theme is what I learned from this problem.
I learned about the applied technique of array sorting. Did beginners wonder, "What is the order of sorting multidimensional arrays (lists in a list)?" This time I will unravel it!
The problem this time is to keep the "city name", "points", and "order" given by the input in a multidimensional array. Since it is necessary to output in ascending order of "city name" in dictionary order, and in descending order of "score" among them, if you output "order" of the list in ascending order in the first and second in descending order of the two-dimensional array It's good. The point is to specify the element you want to sort by lambda expression in the optional argument key. If there are multiple sort keys and the ascending / descending order is different for each, there is a technique to add a minus and invert as shown in the example below. It seems that you can use it if you remember.
Recommended Posts