- 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 ] )

21st Mar 2022, 11:00 PM
ivan gonzalez
ivan gonzalez - avatar
2 Réponses
+ 2
use the built-in function "max()" and "key=len".
21st Mar 2022, 11:12 PM
rodwynnejones
rodwynnejones - avatar
0
Thanks for sahring new knowledge
24th Mar 2022, 10:55 PM
ivan gonzalez
ivan gonzalez - avatar