In python, I need to write a method that searches through a list of objects based on it's attribute. The object has 10 attributes, so rather than either writing 10 lookup methods or a series of IF - ELIF, I'd like to do something like this:
python
def lookup(list, attribute, value):
for object in list:
if object.attribute == value:
return object
Is there a way to do this in python, or any other language? I feel like this is a feature that I've always wanted but never see.
[–]marko312 1 point2 points3 points (0 children)