My current class:
class Animals(object):
def __init__(self):
self.dogs = list()
self.cats = list()
# a lot of species ...
def add_animal(self, animal, category):
if category == 'cats':
self.cats.append(animal)
if category == 'dogs':
self.dogs.append(animal)
# a lot of ifs here ...
I would like to create a universal add_animal method, something like:
def add_animal(self, animal, category):
self[category].append(animal)
How can I achieve it?