Question: python Write a function longest_word that takes a string file_name and returns the longest word in the file with which line it appears on. A
python
Write a function longest_word that takes a string file_name and returns the longest word in the file with which line it appears on. A word here is defined as a sequence of characters and words are separated by white space. If there are ties for the longest word, it should return the one that appears first in the file. If the file is empty or there are no words in the file, the function should return None. You may assume that the file_name describes a file that exists. Suppose we had a file called song. txt with the contents: 1 2. 3 4 Row, row, row your boat Gently down the stream Merrily, merrily, merrily, merrily Life is but a dream! Then the following call would return: 1 longest_word 'song.txt') # '3: Merrily
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
