0
Output the longest word, You mAy use Split.
txt = input() print(txt.split(" ")). I tried upto this. Not working
11 Respostas
+ 4
'''You can do it like this'''
txt = input()
wordslist = txt.split(" ")
''' This makes a list of the words'''
longestword = ""
for word in wordslist:
if len(word) > len(longestword):
longestword = word
''' This checks every word of the list and if it is longer than the selected word it overwrites it'''
print (longestword)
''' https://code.sololearn.com/cynhXHT60v8F/?ref=app '''
+ 3
Well now you need to compare the length of each word with other word like assuming, max=len(list_of_words[0])
if len(list_of_words[1]>max:
max=len(list_of_words)
+ 1
This will help you:
https://code.sololearn.com/cd89N09f7P0R/?ref=app
+ 1
max() sorts strings lexicographically by default.
But it has an optional parameter key that you can use like this:
max(input().split(), key=len)
Detailed explanation:
https://thepythonguru.com/JUMP_LINK__&&__python__&&__JUMP_LINK-builtin-functions/max/
https://www.programiz.com/python-programming/methods/built-in/max
0
But how do I know how mAny Are there.
0
First I need to turn the text into A list. Right. Then I would choose the mAx word using mAx().
0
Wedo Ru by splitting string you can get the length of list which means how many words are there.
0
txt=input (). And what follow next. Kindly, put the code in order.
0
I tried print(max(txt.split(" "))), but it is giving me The Shortest word
0
Yes it will, because you need the longest word (as i showed above how to do that), and max function compares the ascii value of each character for every word.
0
txt = input()
#your code goes here
totaltxt = txt.split()
longest = 0
for i in range(1, len(totaltxt)):
if len(totaltxt[longest]) < len(totaltxt[i]):
longest = i
print(totaltxt[longest])