Jan-26-2022, 11:40 PM
I thought this was interesting. You end up with a list of named tuples.
from collections import namedtuple mylist = ['Finley : 10', 'Evie : 0', 'P1 : 0', 'P2 : 5', 'P1 : 0', 'P2 : 5', 'Finley : 15', 'Evie : 5'] Player = namedtuple('Player', 'name score') tups = [] for m in mylist: alist = m.split() name = alist[0] score = int(alist[2]) tups.append(Player(name, score)) # sort by name or score tups.sort(key=lambda x: getattr(x, 'score'), reverse=True)