Question

In: Computer Science

In Python, Complete the longestWord() function to take a list as a parameter and return the...

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

Solutions

Expert Solution

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


Related Solutions

In Python Complete the function powersOf5(). Have the function take a parameter n and return a...
In Python Complete the function powersOf5(). Have the function take a parameter n and return a list of the first n powers of 5. One way to calculate powers of 5 is by starting with 1 and then multiplying the previous number by 5. Examples: powersOf5( 1 ) returns [1] powersOf5( 2 ) returns [1, 5] powersOf5( 3 ) returns [1, 5, 25] powersOf5( 6 ) returns [1, 5, 25, 125, 625, 3125] powersOf5( 10 ) returns [1, 5, 25,...
In Python Complete the oddNumbers() functions to take an int (as a parameter). Return a list...
In Python Complete the oddNumbers() functions to take an int (as a parameter). Return a list of all of the odd numbers between 1 and one less than the parameter. Also, complete the evenNumbers() functions to take an int (as a parameter). Return a list of all of the even numbers between 2 and one less than the parameter.
Write a Racket function that will take a list of numbers as a parameter and return...
Write a Racket function that will take a list of numbers as a parameter and return true if they all are positive, and false otherwise. You are NOT required to check the type of elements in the list. (please do on racket language)
Write a Racket function that will take a list of numbers as a parameter and return...
Write a Racket function that will take a list of numbers as a parameter and return true if they all are positive, and false otherwise. You are NOT required to check the type of elements in the list.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
python Write a function pack_to_5(words) that takes a list of string objects as a parameter and...
python Write a function pack_to_5(words) that takes a list of string objects as a parameter and returns a new list containing each string in the title-case version. Any strings that have less than 5 characters needs to be expanded with the appropriate number of space characters to make them exactly 5 characters long. For example, consider the following list: words = ['Right', 'SAID', 'jO'] The new list would be: ['Right', 'Said ', 'Jo '] Since the second element only contains...
This is python: #Write a function called count_positive_evens. This function #should take as input a list...
This is python: #Write a function called count_positive_evens. This function #should take as input a list of integers, and return as #output a single integer. The number the function returns #should be the count of numbers from the list that were both #positive and even. # #For example: # # count_positive_evens([5, 7, 9, 8, -1, -2, -3]) -> 1 # count_positive_evens([2, 4, 6, 8, 10, 12, 15]) -> 6 # count_positive_evens([-2, -4, -6, -8, -10, 1]) -> 0 # #0...
Write a Python function that will return the index of an element in a list.1- The...
Write a Python function that will return the index of an element in a list.1- The function will receive a list of at least 5 numbers as a single argument when the function is called. 2. The function will ask the user to input a number and will find and return the index of that number in the list.3. If the number is not an element of the list, the function returns the string "unknown."
Using Python 1. #Now, let's improve our steps() function to take one parameter #that represents the...
Using Python 1. #Now, let's improve our steps() function to take one parameter #that represents the number of 'steps' to print. It should #then return a string that, when printed, shows output like #the following: # #print(steps(3)) #111 #   222 #       333 # #print(steps(6)) #111 #   222 #       333 #           444 #               555 #                   666 # #Specifically, it should start with 1, and show three of each #number from...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT