+ 1
Would you check correct performance of this code ?
The application of this code is to return the longest word among words of a string, but I think in following sample string it doesn't return longest word: https://code.sololearn.com/c6b29g5PP49v/#py find_longest_word ('Python is an interpreted high-level programming language for general-purpose programming. Created by Guido van Rossum and first released in 1991, Python has a design philosophy that emphasizes code readability, and a syntax that allows programmers to express concepts in fewer lines of code,notably using significant whitespace. It provides constructs that enable clear programming on both small and large scales') OUTPUT ---> 'scales' 'scales' is NOT the longest word in above string !!!
3 Antworten
+ 4
I believe your last comment wasn’t intended to be a comment. Try changing that.
You can also use .split(“ “) instead of just .split()
0
By changing .split() to .split(" ") final output will be same ('scales')
But I suppose the code may has not intended performance to find longest word in a string !
0
Here you go. you simply had 'maximum_length = string_length' as a comment!
I also added a line of code to remove . , ! and ? from the string so they don't count to the word lengths.
If you also want to remove the '-' simply add another replace("-", " ")
https://code.sololearn.com/c000G0LgbJh4/#py