Use len()
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-len
Section titled “Sourcery refactoring id: use-len”Description:
Section titled “Description:”Replaces sum() with len where appropriate
Before:
Section titled “Before:”if sum(1 for hat in hats) > 0: self.shout("I have hats")After:
Section titled “After:”if len(hats) > 0: self.shout("I have hats")Explanation:
Section titled “Explanation:”This simplification can be made where the sum() call is effectively just
determining the length of a sized object. It can only be made where Sourcery can
determine that hats supports the __len__() method.