operator.itemgetter

Functions from Python's operator module that build key functions: itemgetter fetches items by index or key and attrgetter fetches attributes.

In more detail

sorted(rows, key=itemgetter('dept', 'salary')) sorts records by department and then salary. They are shorter and slightly faster than equivalent lambda functions.

Related terms

Taught in

References