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

# Simplify Length Comparison

#### Sourcery refactoring id: `simplify-len-comparison`

#### Description:

Removes unnecessarily verbose length comparisons

#### Before:

```python
if len(list_of_hats) > 0:
    hat_to_wear = choose_hat(list_of_hats)
```

#### After:

```python
if list_of_hats:
    hat_to_wear = choose_hat(list_of_hats)
```

#### Explanation:

Something we often do is check whether a list or sequence has elements before we
try and do something with it.

A Pythonic way of doing this is just to use the fact that Python lists and
sequences evaluate to `True` if they have elements, and `False` otherwise.

Doing it this way is a convention, set out in Python's
[PEP8](https://www.python.org/dev/peps/pep-0008/) style guide. Once you've
gotten used to doing it this way it does make the code slightly easier to read
and a bit less cluttered.
