+ 1
Find out the longest word
I want to find out the longest word of a string. However it turnout a TypeError: 'int' object is not iterable. How can I correct the coding? Thanks https://code.sololearn.com/cbKwR5MGZsX5/?ref=app
84 Respuestas
+ 79
text = input().split()
length = [len(x) for x in text]
maximum = max(length)
text_index = length.index(maximum)
print(text[text_index])
+ 56
This should solve it:
txt = input().split()
print(max(txt, key = len))
Cheers m8!
+ 27
https://code.sololearn.com/cJSlK0D24SPT/?ref=app
You can get everything you need to know from here.
+ 22
txt = input()
#your code goes here
txt_list = txt.split(" ")
#print(txt_list)
dictman= {i:len(i) for i in txt_list}
maxman = max(dictman[i] for i in txt_list)
for i in dictman:
if dictman[i] == maxman:
print(i)
+ 15
txt = "this is an awesome text"
#your code goes here
k = txt.split()
j=''
for i in k:
if len(i) > len(j):
j=i
print(j)
+ 7
text = input().split()
new = sorted(text, key=len)
print(new[-1])
+ 3
print(max(k, key=len))
no need for a loop
+ 3
I am still beginning and I was thinking about a cde that doesnt give an erorr if there are more than one longest words:
txt = input("str: ")
splitted_txt = txt.split()
char_numb = (len(p) for p in splitted_txt)
max_char_numb = [max(char_numb)]
for i in splitted_txt:
if len(i) in max_char_numb:
print(i)
Please correct me if there is something wrong in the code. i ran it some times now and it worked well
+ 3
txt = input()
#your code goes here
list = txt.split(' ')
word = ""
for i in list:
if len(i) > len(word):
word = i
print(word)
+ 2
Joe Ma , you can do it this way 🐱
https://code.sololearn.com/c7yXFPkjY4of/?ref=app
+ 1
I don't see how Bahha🐧 solution fails, it prints out the longest word with or without multiple words of the same max length. Their answer is also the most concise.
+ 1
txt = input()
#your code goes here
def l(f):
k=max(f,key=len)
return k
f=txt.split()
print(l(f))
+ 1
Anyone send me c++ projects answers
+ 1
what's wrong with the below code?
txt = input()
Text=txt.split()
#print(Text)
count=0
maxvalue=0
for c in Text:
if len(c) > maxvalue:
maxvalue=len(c)
#print(c)
#print(maxvalue)
count=count+1
if maxvalue==len(c):
print(Text[maxvalue])
break
Test case 1 is getting passed but two is not getting passed. Any idea to resolve this?
+ 1
This worked for me:
txt = input()
#your code goes here
wnum=txt.split(" ")
list=[]
for w in wnum:
list.append(len(w))
maxval=max(list)
print(wnum[list.index(maxval)])
+ 1
text=input()
longest=''
b=list(text.split(" "))
for i in range(len(b)):
if len(b[i]) > len(longest):
longest=b[i]
print()
print(longest)
+ 1
txt = input()
#your code goes here
x = txt.split(" ")
n = [len(i) for i in x]
for i in x:
if len(i) == max(n):
print(i)
+ 1
text = input().split()
length = [len(x) for x in text]
maximum = max(length)
text_index = length.index(maximum)
print(text[text_index])
+ 1
You can see this video for the explanation with full code
Video-> https://youtu.be/FZ0HoOv9rY4
+ 1
txt=input()
print(max(txt.split(), key=len))