All issues PTC-W0015

Unnecessary generator PTC-W0015

Anti-pattern

6 months ago
—
6 months old

Unnecessary generator - rewrite as a list comprehension

```
119 if length != len(b):
120 return False
121
122 types_a = list(type(i) for i in a)123 types_b = list(type(i) for i in b)
124 if types_a != types_b:
125 if types_a[:-1] == types_b[:-1]:
```

Unnecessary generator - rewrite as a list comprehension

```
120 return False
121
122 types_a = list(type(i) for i in a)
123 types_b = list(type(i) for i in b)124 if types_a != types_b:
125 if types_a[:-1] == types_b[:-1]:
126 return _val_eq(a[-1], b[-1])
```

Description

It is unnecessary to use `list`

, `set`

, `dict`

around a generator expression to get an object of that type since there are comprehensions for these types.

```
squares = list(x**2 for x in range(1, 10))
large_numbers = set(n for n in numbers if n > 1000)
tree_counts = dict((tree, counts[tree]) for tree in trees)
```

```
squares = [x**2 for x in range(1, 10)]
large_numbers = {n for n in numbers if n > 1000}
tree_counts = {tree: counts[tree] for tree in trees}
```