Python sorting – A list of objects

somelist.sort(key = lambda x: x.resultType)

Here’s another way to do the same thing that you will often see used:

import operator
s.sort(key = operator.attrgetter('resultType'))

You might also want to look at sorted if you haven’t seen it already. It doesn’t modify the original list – it returns a new sorted list.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)