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
3 Respuestas
+ 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
+ 1
As it is now..it doing exactly what I exacted it to do...but I think you need :-
for i in words.split():
......
......
+ 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.