I would argue that you shouldn't use a list comprehension in this case, and instead use a for
loop:
result = []
for something_that_is_pretty_long in somethings_that_are_pretty_long:
result.append(something_that_is_pretty_long)
One reason to use list comprehensions over a for
loop + .append()
is that it can be much more concise than using an explicit for
loop. However, when the list comprehension needs to be split over multiple lines, that conciseness can make the expression extremely difficult to read.
While PEP8 doesn't explicitly forbid multi-line list comprehensions, the Google Python Style Guide requires that each portion of a list comprehension fit on a single line (emphasis mine):
2.7 Comprehensions & Generator Expressions
Okay to use for simple cases. Each portion must fit on one line: mapping expression, for clause, filter expression. Multiple for clauses or filter expressions are not permitted. Use loops instead when things get more complicated.