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

# Collection to Comprehension

#### Sourcery refactoring id: `collection-builtin-to-comprehension`

#### Description:

Use list, set or dictionary comprehensions directly instead of calling list(),
dict() or set()

#### Before:

```python
squares = list(x * x for x in y)
```

```python
squares = set(x * x for x in y)
```

```python
squares = dict((x, x * x) for x in xs)
```

#### After:

```python
squares = [x * x for x in y]
```

```python
squares = {x * x for x in y}
```

```python
squares = {x: x * x for x in xs}
```

#### Explanation:

The Pythonic way to create a list, set or dictionary from a generator is to use
comprehensions.

Using the comprehensions rather than the methods is slightly shorter, and the
dictionary comprehension in particular is easier to read in comprehension form.
