Skip to content

Use Count

Sourcery refactoring id: use-count

Description:

Replaces sum() with count() where appropriate

Before:

return sum(hat == "bowler" for hat in hats)

After:

return hats.count("bowler")

Explanation:

This simplification can be made where a call to sum() is counting the number of elements that match a condition.