Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started