liveBook · Manning

Sorting algorithm

As explained in Python Workout: 50 ten-minute exercises

Sorting is the technique of arranging elements according to an ordering determined by their values or derived comparison keys.

Sorting is a practical technique for organizing Python data structures. The built-in sorted function handles basic cases, while the key parameter lets you define the value used for ordering. section 3.15

Practice sorting by derived properties:

  • Order positive and negative numbers by absolute value. section 3.15
  • Order strings by their number of vowels. section 3.15
  • Order lists by the sum of their numbers. section 3.15
  • Display Unix shells by decreasing popularity, then sort each shell’s usernames alphabetically. section 3.20

How Python Workout: 50 ten-minute exercises covers it

How deep it goes
Explains sorted and key-based ordering, but stops short of algorithm internals or implementation details.
Examples
Uses absolute values, vowel counts, nested-list sums, repeated vowels, and Unix shell popularity as sorting criteria.
What it assumes
Builds on Python lists, tuples, and functions while extending sorting beyond straightforward built-in use.
What you can do after
Apply it via Python’s sorted function and key parameter to order data by custom properties.
How it connects
Ties sorting to Python data structures, key functions, lambda expressions, and passing functions to other functions.

Also explained in

Compare how 18 books explain sorting algorithm →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python Workout: 50 ten-minute exercises. The section links point to the parts of the book it draws on.