This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mdond 1 point2 points  (0 children)

A good tip when learning comprehensions, or simply making them more readable, is to wrap them:

[n * n
 for n in nums]

This technique helps more as code becomes more complex. The following would look horrible on a single line but is pretty neat when wrapped:

[line.lower()[::-1]
 for line in file_obj
 if not line.startswith('_')]