Question: Hello, Reads the file with filename into your function and returns the longest word in the text file. - Words are separated by whitespace characters,
Hello,
Reads the file with filename into your function and returns the longest word in the text file. - Words are separated by whitespace characters, but does not include the following punctuation characters (,.!?;). You can assume contractions count as one word (i.e. "don't", "you'll", etc. are one word). - In the case of a tie, the 1st occurrence of the longest word is returned. - The split and strip functions may be useful. - Your function should open the file for reading, and close the file before returning.
I have below this code but cannot seem to pass the test functions. 
def longestWord(filename): maxword = '' with open(filename, 'r') as x: for line inx: linelist line.splitO word in linelist: if len(word) len(maxword): maxword -word return maxword
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
