0

What is another method?

Longest Word Given a text as input, find and output the longest word. Sample Input this is an awesome text Sample Output awesome Longest Word My solving: txt = input() v=txt.split() print(max (v,key=len)) What is another decision could be? may be more manule, not via max?

25th Mar 2022, 9:12 AM
Askar Kondybaev
Askar Kondybaev - avatar
9 Answers
+ 2
You may try something like this txt = input().split() longest = txt[0] for word in txt: if len(word) > len(longest): longest = word print(longest)
25th Mar 2022, 9:36 AM
Simba
Simba - avatar
+ 2
Askar Kondybaev , it could also be done by using sorted() with key= len, but i think this is not what you wanted. txt = "this is major tom to ground control".split() print(sorted(txt, key=len)[-1]) to learn the basics, the sample from Simba is a good choice. happy coding!
25th Mar 2022, 11:39 AM
Lothar
Lothar - avatar
+ 2
Iris Salvation This is learning platform so it would be better if you ask your programming problem.
26th Mar 2022, 2:57 AM
A͢J
A͢J - avatar
+ 1
Simba, i think it is the best original solving.
26th Mar 2022, 8:11 AM
Askar Kondybaev
Askar Kondybaev - avatar
0
Actually there no method that is follow from studied materials of "More Types" (Phyton Core) topic.
25th Mar 2022, 9:31 AM
Askar Kondybaev
Askar Kondybaev - avatar
0
Amir javadikia What is the difference between your code and shared code with question? Your example is same as his example..
25th Mar 2022, 9:53 AM
A͢J
A͢J - avatar
0
Ok i deleted it
25th Mar 2022, 10:16 AM
Amir javadikia
Amir javadikia - avatar
27th Mar 2022, 6:02 AM
Pranav
Pranav - avatar
- 1
Pls am new here can I make new friends
25th Mar 2022, 10:57 PM
Iris Salvation