Reputation: 271
I am trying to read in a file and convert its contents to lowercase then write it back out all lowercase in the same fashion / order ( one word per line and the lines are in alphabetical order ) to a new file.
Ultimately, what I am trying to do is to convert all the lines in this life to lowercase letters.
Why isn't this python script doing this and how can I do this in Python 2.7:
from itertools import chain
from glob import glob
lines = set(chain.from_iterable(open(f, 'rU') for f in glob('./files/*.txt')))
with open('listTogether.txt', 'w') as out:
for line in lines:
line.lower()
out.writelines(sorted(lines))
Upvotes: 1
Views: 7055
Reputation: 99640
You are not replacing the line.lower()
back into the list.
Try:
lines = [line.lower() for line in lines]
with open('listTogether.txt', 'w') as out:
out.writelines(sorted(lines))
Upvotes: 3