Reputation: 1177
In Python 2.7 I would like to know how to add a whitespace between every single character in a .txt file (very big file). I know how to do it with Emacs but is very slow.
Input example:
122212121212121
212121212121212
121212121212121
Expected output:
1 2 2 2 1 2 1 2 1 2 1 2 1 2 1
2 1 2 1 2 1 2 1 2 1 2 1 2 1 2
1 2 1 2 1 2 1 2 1 2 1 2 1 2 1
Upvotes: 1
Views: 78
Reputation: 20336
Try this:
with open(infile) as open_file:
with open(outfile, 'w') as write_file:
for line in open_file:
write_file.write(" ".join(line))
Upvotes: 4