Use Count
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 refactoring id: use-count
Section titled “Sourcery refactoring id: use-count”Description:
Section titled “Description:”Replaces sum() with count() where appropriate
Before:
Section titled “Before:”return sum(hat == "bowler" for hat in hats)After:
Section titled “After:”return hats.count("bowler")Explanation:
Section titled “Explanation:”This simplification can be made where a call to sum() is counting the number
of elements that match a condition.