Nov-29-2020, 04:35 AM
Hi everyone,
I feel like I'm close to an answer for this one.. but not quite. Would groupby be the way to go here?
Source: https://courses.cs.washington.edu/course...part1.html
Problem 6.b: Longest Word
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. 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 poem.txt with the contents:
she sells
sea
shells by
the sea shore
Then the following call would return:
longest_word('poem.txt') # '3: shells'
Because the longest word is "shell"s and appears on line 3.
I feel like I'm close to an answer for this one.. but not quite. Would groupby be the way to go here?
Source: https://courses.cs.washington.edu/course...part1.html
Problem 6.b: Longest Word
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. 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 poem.txt with the contents:
she sells
sea
shells by
the sea shore
Then the following call would return:
longest_word('poem.txt') # '3: shells'
Because the longest word is "shell"s and appears on line 3.