Skip to content

unpacked-list-comprehension (UP027)#

Derived from the pyupgrade linter.

Fix is always available.

What it does#

Checks for list comprehensions that are immediately unpacked.

Why is this bad?#

There is no reason to use a list comprehension if the result is immediately unpacked. Instead, use a generator expression, which is more efficient as it avoids allocating an intermediary list.

Example#

a, b, c = [foo(x) for x in items]

Use instead:

a, b, c = (foo(x) for x in items)

References#