3 ms·
attrgetter takes an attribute name and returns a function that, when passed an object, returns that attribute from that object. So it's a curried getattr. The
by apendleton 14y ago
attrgetter takes an attribute name and returns a function that, when passed an object, returns that attribute from that object. So it's a curried getattr. These are equivalent:
f = attrgetter("some_property")
f = lambda obj: getattr(obj, "some_property")