Shan
Shan

Reputation: 381

Sorting multiple attributes of lists at a time in python?

I have a tuple that represents a person contains an (ID, overall score, days employed, peer score).

I have decided to put each tuple in a list as follows:

aList = [ aTup, bTup, cTup.....]

I would like to rank people from best to worst based on the rules below. The rules are as follows:

1. People(in this case the tuples) are sorted based on their overall score.
-->If the overall score is the same, sort it by the number of days employed. 
-->If the days employed is the same, sort by peer score.
-->If the peer score is the same, sort by ID(the smaller ID gets preferenced.

Is there a method in python that allows me to achieve this? Something close to the .sort() method?

Upvotes: 0

Views: 32

Answers (1)

DeepSpace
DeepSpace

Reputation: 81684

The default sort() actually does that for tuples. You only need to make sure that your tuples are of the form (score, days_employed, peer_score, id).

Upvotes: 1

Related Questions