- 1
Find largest word in a text
txt = #text you want #your code goes here txt = txt.split( " " ) arrWords = [] arrLenWords = [] #Let´s get max number, from here get position of word for i in txt: i = i.replace(",","") arrWords.append( i ) for words in arrWords: arrLenWords.append( len(words) ) pos = 0 for j in arrLenWords: pos = arrLenWords.index(max(arrLenWords)) print( arrWords[ pos ] )
2 ответов
+ 2
use the built-in function "max()" and "key=len".
0
Thanks for sahring new knowledge