Sahaj.blogs

Day page

21 Sept 2023

Study

Python · Comprehensions

List, dict and set comprehensions, filtering with if, nested loops, and when a generator expression is the better choice.

  • A comprehension reads like the loop it replaces: expression, then for, then an optional if.
  • Inside sum() or any(), a generator expression avoids building a whole list in memory.

Read the post →