Comprehensible Comprehensions
summary
Explains that list comprehensions are a concise tool for transforming one iterable into another and nothing else, shows how to copy/paste a for-loop into a comprehension, and demonstrates generator expressions (parentheses instead of brackets) as the right choice when the result is iterated only once. Covers set and dict comprehensions, using the list constructor or dict() instead of pointless comprehensions, warns against side effects like print inside comprehensions, and recommends to break comprehensions over multiple lines for readability.
AI-written summary · about
chapters (11)
- 0:00Start
- 2:15Definitions
- 3:30for loops
- 5:46Breaking it down
- 6:37Copy-pasting into a comprehension
- 8:49Breaking up the components
- 15:27Generator Comprehensions
- 16:34Generator Expression Syntax
- 18:28Loop over them right away
- 22:20Don't abuse comprehensions
- 26:55Not filtering or changing anything?
related talks
33mComprehensible Comprehensions
02h 18mComprehending comprehensions
03mComprehending Comprehensions
07mOptimizing with list comprehensions
21mBecome a Better Pythonista by Abusing List Comprehensions and :=
25mLazy Looping: The Next Iteration
42mLovely for-comprehensions: Scala's most useful syntactic tool
15mPythonic FuncProg: List comprehensions
