In this chapter, you learned the following:
Generator expressions yield items lazily (on demand), which saves memory for large datasets; pass them directly to aggregators like sum rather than materializing intermediate lists.
Python offers iterator-centric helpers beyond basic loops. Most itertools functions and reversed return iterators you can feed into for loops, comprehensions, or other consumers, while sorted returns a list.
Built-ins like enumerate and zip are iterators that pair indexes with values or walk multiple sequences in lockstep, handy for labeled iteration and managing parallel lists.
Lambda functions passed to map and filter are useful for quick predicate checks (for example, “starts with #”) and simple transformations (for example, “strip the first char”).
You can prototype simple text “summaries” by chaining itertools tools: tokenize, make word-pairs with combinations, flatten with chain.from_iterable, count with Counter.most_common, and keep frequent pairs with takewhile.
For ordering, reversed just flips the existing order, while sorted actually orders by value. Python won’t sort heterogeneous types unless you supply a key function.