Order Players by multiple values
Posted: Fri Sep 16, 2016 3:58 pm
Hey,
I was wondering how I can create a dict which is sorted by multiple arguments (INT).
So lets say I have a class
dict for all players
And now I need to return a list of all players, which have isActive and, are ordered by level (INT/ASC-Highest first, Lowest last) and by inStart the opposite (INT/DESC, Lowest first, highest last)
So in the end it could look like:
Thanks
I was wondering how I can create a dict which is sorted by multiple arguments (INT).
So lets say I have a class
Syntax: Select all
class Player(object):
def __init__(self, account_name, isActive, level, inStart):
self.name = account_name
self.isActive = isActive
self.level = level
self.inStart= inStart
dict for all players
Syntax: Select all
players = {0: Player('Sir Lancelot', True, 2, 0),
1: Player('Sir Gallahad', False, 1, 1),
2: Player('Sir Robin', True, 2, 1),
3: Player('King Arthur', True, 1, 0),
4: Player('Robin Hood', True, 3, 1)
}
And now I need to return a list of all players, which have isActive and, are ordered by level (INT/ASC-Highest first, Lowest last) and by inStart the opposite (INT/DESC, Lowest first, highest last)
So in the end it could look like:
Code: Select all
Robin Hood
Sir Robin
Sir Lancelot
King Arthur
Thanks