← TechnologyThe essentials of

Itemgetter: selecting a field for sorting

Publisher: ResumeMaker • 1 source

Published: 22 Oct 2026 16:11 · Updated: 22 Oct 2026 16:11

AI source check: 22 Oct 2026 14:04. This is not editorial approval.

In a few sentences

In brief

operator.itemgetter('price') creates a function that retrieves the specified key. It can serve as the key argument to sorted() instead of another small custom function.

Useful to know

operator.itemgetter('price') creates a function that retrieves the specified key. It can serve as the key argument to sorted() instead of another small custom function. [1]

First check that records contain comparable prices. Retrieval neither converts text to numbers nor supplies missing keys. If sorting needs a secondary criterion, include it in the explicit rule rather than relying on an accidental property of the input.

Sources

For further detail and to check the information:

  1. [1] operator — Standard operators as functions — Python 3.12.15 documentation ↗