Loading topic
for loop over range and other iterables, use append on a list, and read a basic comparison such as n > 3. The previous chapter showed the loop-to-comprehension rewrite once. Here you learn the syntax precisely, so you can predict what any list comprehensi5 min read[expr for item in iterable]) and that you know Python's comparison operators, and/or/not, and truthiness. By the end you will be able to add a trailing if to any comprehension. You will also be able to predict which items it ke6 min readif filter works, and are comfortable with comparison operators and Python's one-line conditional expression, a if condition else b. The previous chapters covered filtering. Here you will learn the other place an `6 min readfor loops with range, and that you know lists, dictionaries, and sets as built-in types. It also assumes you can write boolean conditions and already know list comprehensions, including the trailing if filter and the if/else conditional expression. A dict6 min readset from any iterable in one expression. You write it like a list comprehension, but with curly braces and a single output expression. This chapter covers the syntax, what changes because the result is a set, and the errors that come from sets being unordered and hash-6 min readif. You should also be comfortable with nested lists, tuples, and for loops. Here you will learn to put several for clauses in one comprehension, read them in the right order, and use them t7 min readfor loops, range, and building lists, dicts, and sets. You should also know the basic comprehension forms from earlier chapters, including the trailing if filter. This chapter covers the scope rules behind them: which names a comprehension can see, which names it7 min readif filters. It also assumes you know that a comprehension has its own scope (covered earlier in this tutorial). You need Python 3.8 or later to run the examples.7 min readif filters and conditional expressions. It also assumes you have seen multiple for clauses and generator expressions. The goal is to decide when not to use them. A comprehension is a tool for building a collection6 min read