Question: PYTHON ONLY, NEED ASAP! Q5 - Function II: string_shortener () (1.5 points) Define a function string_shortener() that takes two parameters as inputs (a list of
PYTHON ONLY, NEED ASAP!
Q5 - Function II: string_shortener () (1.5 points) Define a function string_shortener() that takes two parameters as inputs (a list of strings) and int_list (a list of integers). Within the function, your code should extract the number of characters in each element of as specified by the integer in the corresponding element in int_list, adding each shortened string to output_list (which should be return ed from the function.) For example, if the first element in str_list were 'hello' , and the first element in int_list were 3 , the string (the first three letters of should be added to One caveat, is that if the integer specified in int_list is greater than the number of characters in the corresponding element in then should be added to (instead of a shortened string). For example: - string_shortener(str_list=['hello', 'hey', 'everything'], int_list=[3, 2, 5]) should return ['hel', 'he ', 'every'] - string_shortener(str_list=['somanyletters', 'everything'], int_list=[40, 17]) should return [None, None] Notes: - you can assume that the length of both inputs is the same (your code does NOT have to check for/account for this) - you can assume that str_list contains a list of strings and contains a list of integers (your code does NOT have to check for/account for this) - the output_list should always have the same number of elements as the input parameter lists - remember that zip(), introduced on A4, is available for use. This question can be completed without ...but it may be simpler if you use zip()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
