Not.
Explanations of lists are by definition no longer pythonic than simple loops - only if these loops are for creating new lists (or dicts, sets, etc.), and if listcomp is easier to read than a loop.
This is not the case in your example (you are not building anything), and you should not use listcomp only for your side effects, which would be clearly non-python.
So good to convert
result = [] for line in lines: result.append(line.upper())
in
result = [line.upper() for line in lines]
but not your example.
source share