In the process of writing a project, you can always find a sort of dictionary, and if you want to implement a multiple-condition ordering, you need only the following lines of code to implement. Fully embodies the benefits of Python.
Copy Code code as follows:
Teamitems = [{' Team ': ' France ', ' P ': 1, ' GD ': -3, ' GS ': 1, ' GA ': 4},
{' Team ': ' Uruguay ', ' P ': 7, ' GD ': 4, ' GS ': 4, ' GA ': 0},
{' Team ': ' SouthAfrica ', ' P ': 4, ' GD ': -2, ' GS ': 3, ' GA ': 5},
{' Team ': ' Mexico ', ' P ': 4, ' GD ': 1, ' GS ': 3, ' GA ': 2}]
Print sorted (teamitems, key = lambda x: (x[' P '],x[' GD '],x[' GS '],x[' GA ')), reverse=true)
The above code is implemented by ' P ', ' GD ', ' GS ', ' GA ' four conditions sorted, Reverse=true Express Descending
Of course I can.
Copy Code code as follows:
From operator Import Itemgetter
Print sorted (teamitems, key = Itemgetter (' P ', ' GD ', ' GS ', ' GA '), reverse=true)