Question: Write the shorten_words() function which is passed a list of strings as a parameter. The function replaces every string in the parameter list which is
Write the shorten_words() function which is passed a list of strings as a parameter. The function replaces every string in the parameter list which is longer than four letters with its initial four letters, e.g., the word "balloon" is replaced by "ball", the word "initial" is replaced by "init", the word "revival" is replaced by "revi". Any element which has fewer than five letters is left unchanged.
For example, executing the following code with the completed shorten_words() function:
words = ["egg", "go", "fuddy-duddy", "hi", "hubbub"] shorten_words(words) print("1:", words) words = ["flippant", "fiasco", "earwig", "brouhaha", "zoo"] shorten_words(words) print("2:", words) prints:
1: ['egg', 'go', 'fudd', 'hi', 'hubb'] 2: ['flip', 'fias', 'earw', 'brou', 'zoo']
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
