Python comprehensions are a concise way to create new collections while transforming or filtering elements. However, using a comprehension that
copies elements from one collection to another without any transformation is less readable than using the respective constructor directly.
Therefore, when a comprehension is only copying elements, use the appropriate constructor instead:
- Replace
[x for x in iterable]
with list(iterable)
- Replace
{x for x in iterable}
with set(iterable)
- Replace
{k: v for k, v in iterable.items()}
with dict(iterable)