Would you check correct performance of this code ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 !!!

17th Feb 2018, 10:40 PM
NIMA
NIMA - avatar
3 Answers
+ 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()
17th Feb 2018, 11:08 PM
Pedro Demingos
Pedro Demingos - avatar
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 !
17th Feb 2018, 11:13 PM
NIMA
NIMA - avatar
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
18th Feb 2018, 1:16 PM
David Handl
David Handl - avatar