# Comprehensions and Sorting

Comprehensions and Sorting: Comprehensions: New Lists in One Line, Sorting with key and lambda.

Updated: November 19, 2026

1. [Comprehensions: New Lists in One Line](https://www.ask-codey.com/lessons/python-comprehensions) (Apprentice): A comprehension builds a new list, dictionary or set from another collection in one line, written as what goes in, for each item, if a condition holds, and replaces the empty-list-and-append loop whenever the whole job is building one collection.
2. [Sorting with key and lambda](https://www.ask-codey.com/lessons/python-sorting-with-key-and-lambda) (Journeyman): sorted() takes a key, a function it calls on each item to get the value to compare, so a short lambda can sort recipes by their minutes or a dictionary's entries by their values, from largest to smallest with reverse=True.

Source: https://www.ask-codey.com/courses/python-in-depth/topics/python-comprehensions-and-sorting
