I want to read a text file and extract each word from all lines to make a list of strings like below:
['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'breaks', 'east',
'envious', 'fair', 'grief', 'is', 'kill', 'light', 'moon', 'pale', 'sick',
'soft', 'sun', 'the', 'through', 'what', 'window', 'with', 'yonder']
I wrote this code:
fname = raw_input("Enter file name: ")
fh = open(fname)
lst = list()
for line in fh:
lst.append(line.split())
print lst
print lst.sort()
when I sort it in the end it gives nothing but a None. I get this unexpected result!
[['But', 'soft', 'what', 'light', 'through', 'yonder', 'window', 'breaks'],
['It', 'is', 'the', 'east', 'and', 'Juliet', 'is', 'the', 'sun'], ['Arise',
'fair', 'sun', 'and', 'kill', 'the', 'envious', 'moon'], ['Who', 'is',
'already', 'sick', 'and', 'pale', 'with', 'grief']]
None
I am totally lost. What I am doing wrong?