- 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.

22nd May 2021, 8:40 PM
Hammad Karim
Hammad Karim - avatar
1 Answer
+ 2
Hammad Karim Yes, Just in two lines list = txt.split(' ') print (max(list, key = len))
22nd May 2021, 8:50 PM
A͢J
A͢J - avatar