4 Réponses
+ 3
This is what I did...
txt = input()
#this attaches the user input to the variable txt
longest = txt.split()
#.split() takes one large string and separates it into a sortable list
longest_word = max(longest, key=len)
'''This is the tricky part.
max() takes the largest values.
longest is the split variable of the input.
key=len will organize them from smallest to largest.
example = [1,22,0000]
max(example, key=len) = 0000 as the largest.
Alternatively could key=len and take longest[-1] since it was organized from smallest to largest, is largest is at the end of the list.
simple doing longest_word = max(longest) from what I can tell takes in longest[0], so doing key=len forces it to actually go through the list fir the largest word'''
print(longest_word)
#prints the longest word found
there, now you did it with just 4 lines of code.
+ 8
Because b=b+1 should be inside while loop not outside of it.
+ 5
Thank you
+ 2
Thank you Catalyst, for very good explanation