Description
We all know that the time to buy things, the site will be given a lot of merchandise on the electricity supplier website according to our search criteria. These items will be ordered in accordance with a certain kind of collation, turn in front of us. Now a book about electricity supplier website Sort There are so few, integrated sales, publication date, price, user rating. Ranking assume the rule is: First look at the price, low price of the top-ranking, if the price is the same, the time of publishing, publishing rankings of late forward, if both are the same then look at sales, sales of large front if the first three are the same, and finally see user ratings, higher user ratings ranking.
Please write a book based on the rules to each program on a consolidated ranking.
Input
Conduct a first integer n (1 <n <100), followed by n rows book data, a total of 7, separated by spaces between each column. Wherein the first listed title (length of less than 60 and containing only uppercase and lowercase letter string), the second column to the seventh column are equal to an integer greater than 0, representing sales book, published in time , month, date, price and user rating.
Output
Sample Input Copy
3
CPrimerPlus 3000 2013 12 6 60 44
ComputerSystemsAProgrammersPerspective 8000 2015 3 12 156 39
TheCProguammingLanguage 50000 1978 2 22 5 46
Sample Output Copy
TheCProguammingLanguage 50000 1978 2 22 5 46
CPrimerPlus 3000 2013 12 6 60 44
ComputerSystemsAProgrammersPerspective 8000 2015 3 12 156 39
Python fourth Oj have such a problem. The default sort function to a comparison of the first, if nested conditional sort of words are too cumbersome, people look at this code is also feeling a little dizzy. Think of the sort function has a key argument can call the function returns an iterator object, so I think there are ways to achieve multi-level comparison of key parameters. Access to information discovery of two ways.
1.lambda returns a tuple
The general form of lambda lambda keyword is followed by one or more parameters, followed by a colon, the future is an expression. lambda is an expression rather than a statement. It can appear in places like the Python syntax does not allow def arise. As expression, lambda returns a value (i.e., a new function). lambda used to write a simple function, but def more powerful to handle tasks.
Example: lambda] 1 using [
1, the general form
f = lambda x, y, z :x+y+z
print f(1,2,3)
#output:6 *②
2.itemgetter
What dimensional data, operator function parameters itemgetter module provides for a number of the object for acquiring the serial number. See the examples below
Example:
from operator import itemgetter
a = [1,2,3]
b = operator.itemgetter (1,0) // define the function b, obtaining a first object and a field value of 0
>>> B (A)
(2,. 1)
To note, operator.itemgetter not function gets the value, but the definition of a function, in order to get the value of the object via the function role. * ③
Example:
sorted(student_tuples, key=itemgetter(1,2))
itemgetter parameter is a list of dictionary index or index arranged in ordered by priority * ④
references:
①https: //blog.csdn.net/w417950004/article/details/86253721 (multi-level sorting)
②https: //www.cnblogs.com/mxh1099/p/5386529.html (lambda expressions)
③https: //www.cnblogs.com/zhoufankui/p/6274172.html (itemgetter function)
④https: //blog.csdn.net/jb19900111/article/details/50649932 (sort, sorted advanced sorting)