Reputation: 11
Is there any way of checking through a list of objects to see if any of them have a specific value for an attribute (or attributes). Let's say you wanted a program to see if there were any cabinets in a list of cabinets that were 40 inches tall and 50 inches wide. Does python have a way of finding that?
Upvotes: 0
Views: 107
Reputation: 99620
You can use a list comprehension:
object_with_specific_attribute = [obj for obj in object_list if obj.length == 40 and obj.width == 50]
Upvotes: 2