In: Computer Science
In Python,
Complete the longestWord() function to take a list as a parameter and return the length of the longest word in that list.
Examples:
longestWord(['Python', 'rocks']) returns 5
longestWord(['Casey', 'Riley', 'Jessie', 'Jackie', 'Jaime', 'Kerry', 'Jody']) returns 6
longestWord(['I', 'a', 'am', 'an', 'as', 'at', 'ax', 'the']) returns 3
#function for calculating maxilength word
def longestWord(lst):
maxlength=0
for word in lst:
if(maxlength<len(word)):
maxlength=len(word)
return maxlength
#main program
#crreating user defined list
n=int(input("enter number of strings : "))
lst=[]
for i in range(n):
inpt=input("Enter item : ")
lst.append(inpt)
#calling function
print(longestWord(lst))