Simplify-Constant-Sum
Documentation Index
Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
Use this file to discover all available pages before exploring further.
Sourcery rule id: simplify-constant-sum
Section titled “Sourcery rule id: simplify-constant-sum”Description
Section titled “Description”Simplify constant sum() call
Before
Section titled “Before”sum(1 for book in books if book.author == "Terry Pratchett")sum(bool(book.author == "Terry Pratchett") for book in books)Explanation
Section titled “Explanation”As sum add the values it treats True as 1, and False as 0. We make use
of this fact to simplify the generator expression inside the sum call.