From 9c25cc7a10d59a0c6c01cb89e0468885e34da4be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=A3=D8=AD=D9=85=D8=AF=20=D8=A7=D9=84=D9=85=D8=AD=D9=85?= =?UTF-8?q?=D9=88=D8=AF=D9=8A=20=28Ahmed=20El-Mahmoudy=29?= Date: Wed, 18 Mar 2026 10:30:41 +0100 Subject: [PATCH] Change animals_by to accept any key equivalent to to an animal attribute Hence 'legs' would be changed to 'number_of_legs', I think that makes the code more elegant --- ch09-objects/e45b3_color_and_legs.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ch09-objects/e45b3_color_and_legs.py b/ch09-objects/e45b3_color_and_legs.py index ecc8f58..150fb58 100755 --- a/ch09-objects/e45b3_color_and_legs.py +++ b/ch09-objects/e45b3_color_and_legs.py @@ -76,5 +76,4 @@ def animals_by(self, **kwargs): return [one_animal for one_cage in self.cages for one_animal in one_cage.animals - if (('color' in kwargs and one_animal.color == kwargs['color']) and - ('legs' in kwargs and one_animal.number_of_legs == kwargs['legs']))] + if all(key in vars(one_animal) and getattr(one_animal,key) == kwargs[key] for key in kwargs)]