Suggestions | Sololearn: Learn to code for FREE!

-1

Suggestions

This is problem: Given a text as input, find and output the longest word. Sample Input this is an awesome text Sample Output awesome This is my solution: txt = input() d = txt.split(" ") i = [] for c in d: v = len(c) i.append(v) o = max(i) f = i.index(o) print (d[f]) If there is any other solution shorter then it. Please tell me.

5/22/2021 8:40:34 PM

Hammad Karim

1 Answer

New Answer

+2

Hammad Karim Yes, Just in two lines list = txt.split(' ') print (max(list, key = len))