The itemgetter
function from Python's operator
module creates a callable that retrieves items from objects using indices (for sequences like lists/tuples) or keys (for mappings like dictionaries). It is efficient and commonly used with functions like sorted()
, max()
, and min()
for clean, readable code.
from operator import itemgetter
- Basic Usage with a List