read a file and split the words python 1

read a file and split the words python

f = open("yourfile.txt", "r")

content = f.read()
words = content.split()

f.close()

Here is what the above code is Doing:
1. Open the file in read mode
2. Read the file’s contents
3. Split the contents into a list of words
4. Close the file

Similar Posts