I don't understand the logic of this function. it is as if it said that the variable by itself is greater than the variable | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I don't understand the logic of this function. it is as if it said that the variable by itself is greater than the variable

https://code.sololearn.com/ciZEzR6yJDwP/?ref=app

28th Dec 2020, 12:23 AM
luis morales
luis morales - avatar
3 Answers
+ 4
if you supply it with a list of words, it will go through each word and test it against the last. If the new word is longer than the previous word, it becomes the new longest word. The function then returns the longest word. so: word = find_word("Hi my name is Slick wonderful to meet you!".split()) print(word) # output wonderful
28th Dec 2020, 12:35 AM
Slick
Slick - avatar
+ 1
As it is now..it doing exactly what I exacted it to do...but I think you need :- for i in words.split(): ...... ......
28th Dec 2020, 12:38 AM
rodwynnejones
rodwynnejones - avatar
+ 1
this function will return the object in 'words' which have the biggest length. it compares the length of the objects, not the objects themselves. initially you suppose that the longest word 'more_large' is the empty word "", then you compare the length of each element 'i' of 'words' to the length of the supposed longest word 'more_large'. if the length of 'i' is greater than the length of the supposed longest word then 'i' will be the new 'supposed' longest word. it's a classic algorithm to find the max and min of a list of objects.
28th Dec 2020, 12:42 AM
John Robotane
John Robotane - avatar