Just to preface this, I've already checked out posts pertaining to this question and they haven't fully answered mine.
So I would just like to know how to sort a list of objects based on their attributes in two ways:
- if the attribute is a string (to alphabetize)
- if the attribute is a integer (to do by numerical order)
This is my list of classes:
mainList = [
hero( name='SirGoose', classes='Fighter', level=150 ),
hero( name='Conan', classes='Barbarian', level=160 ),
hero( name='KingArthur', classes='Knight', level=170 )
]
So what I'm really looking for is a way to sort this list to that the hero's names are sorted in alphabetical order, then another method for level. Thank you!