+ 1
Help me. I tried this code for longest word in python. I even succeeded in the first 3 tests but failed in the last one.
txt = input() data = txt.split(" ") for x in data : a = str(len(x)) if str(len(x)) != str(max(list(a))) : print(x) break Pls help me to solve.
3 Answers
+ 2
Here's a possible solution:
a = input().split()
b = max([len(x) for x in a])
[print(x) for x in a if len(x) == b]
# Hope this helps
+ 7
Ritesh Behera ,
âȘïžhere is an other possible solution. it splits the input to a list, then these list is sorted with length of the words as key:
res = input().split()
print(sorted(res,key=len)[-1])
âȘïžan other (more simple) solution by using max could be:
a = input().split()
print(max(a, key = len))
max has an optional parameter "key" that can be used.
+ 1
Thnx broo