> ## 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.

# Use len()

#### Sourcery refactoring id: `use-len`

#### Description:

Replaces `sum()` with `len` where appropriate

#### Before:

```python
if sum(1 for hat in hats) > 0:
    self.shout("I have hats")
```

#### After:

```python
if len(hats) > 0:
    self.shout("I have hats")
```

#### 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.
