Question: Define a function named get_longest_word_list (words_list, target_letters) which takes a list of words and a string of letters as parameters and returns a list
Define a function named get_longest_word_list (words_list, target_letters) which takes a list of words and a string of letters as parameters and returns a list of words. For each letter in the target_letters parameter, the function finds the longest word in the parameter, words_list, that contains that particular letter. The longest word that contains the letter is inserted into the returned list at the position that corresponds to the position of the letter in the target_letters parameter. The new list should contain n words where n is the number of letters in the target_letters parameter and the ith element is the longest word that contains the ith letter specified in the target_letters parameter. For example: print (get_longest_word_list(['this', 'is', 'a', 'very', 'short', 'sentence'], 'er')) produces: ['sentence', 'short'] The longest word that contains the letter 'e' is 'sentence' and the longest word that contains the letter 'r' is 'short'. For example: Test a_list = ['this', 'is', 'a', 'very', 'short', 'sentence', 'but', 'it', 'is', 'also', 'a', 'very', 'useful', 'example']['short', 'sentence print (get_longest_word_list (a_list, 'os')) Result
Step by Step Solution
3.31 Rating (160 Votes )
There are 3 Steps involved in it
The function definition in the image is for the function getlongestwordlist This function takes two parameters 1 wordslist A list of words 2 targetletters A string of letters The function returns a li... View full answer
Get step-by-step solutions from verified subject matter experts
