Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What are the advantages and disadvantages of left-deep trees?

Answered: 1 week ago

Question

2. Outline the functions of nonverbal communication

Answered: 1 week ago