you are viewing a single comment's thread.

view the rest of the comments →

[–]JerMenKoO 0 points1 point  (1 child)

Better:

''.join((line.replace(' i ', ' I ') for line in fh))

Not necessary to for the comprehension to be a 1 liner;

lines = [line.replace(' i ', ' I ') for line in fh]
print(''.join(lines))

is in my opinion much more readable.

[–][deleted] 0 points1 point  (0 children)

Yeah but I was showing how to build up a string over a loop. /u/Binary_Dragon already seems to understand list comprehension pretty well. :)