Question: ) The second way to read text from a file is shown in the middle of p. 113. On line 7 of that listing we

 ) The second way to read text from a file is

) The second way to read text from a file is shown in the middle of p. 113. On line 7 of

that listing we see: wordList = content.split()

What does the .split() method do, and what is stored in wordList as a result?

def numWords (filename): 'returns the number of words in file filename' infile = open(filename, 'r') content = infile.read() # read the file into a string infile.close() wordList = content.split() print (wordList) return len(wordList) # split file into list of words # print list of words too

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!