>>> [line.split() for line in open('File.txt')]
[['hi'], ['hello'], ['cat'], ['dog']]
Or, if we want to be more careful to make sure the file is closed:
>>> with open('File.txt') as f:
... [line.split() for line in f]
...
[['hi'], ['hello'], ['cat'], ['dog']]
source
share