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 maxwordStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started