0

How can I sort a list that contains classes by a particular instance variable? I want to do alphabetically by the name of the animal in this case.

For example: my_list = [Animal('dog',3), Animal('cat',5) , Animal('bird',2)]

I want it sorted like this: [Animal('bird',5), Animal('cat',3), Animal('dog',2)] (Alphabetically)

I don't want it like this: [Animal('bird',2), Animal('dog',3), Animal('cat',5)] (Numerically)

Ersel Er
  • 731
  • 6
  • 22

0 Answers0