+ 2

I need help please to solve the longest_word qauiry in Python

Python qauiry

6th May 2022, 4:18 PM
Shamson Yacoub
Shamson Yacoub - avatar
2 Answers
+ 4
Shamson Yacoub , are you looking to find the longest word in an input sentence? if YES: there are several approaches to do so: - using a for loop ... - using the max() function ... to get the longest word, we have to check each word. to do so, we split the input sentence at the word boundaries (spaces). the result is a list of individual words. using a for loop: we can iterating now through the words list, calculating the length of each word. since we have to memorize the properties length and word, we need a variable like max_word ( list) in each iteration step, we need to check if the current word is longer then the ones stored temporarily in max_word. if yes, max_word will get the new values. at the end of the iteration, max_word contains the the longest word and its length.
6th May 2022, 5:18 PM
Lothar
Lothar - avatar
+ 3
Plesse show your attempt with a question.
6th May 2022, 5:18 PM
JaScript
JaScript - avatar