Question: Please solve it by Python 3 Imagine that we have the following list of words: ['Mirror', 'Mirror', 'on', 'the', 'wall'] There are 5 words in

Please solve it by Python 3

Imagine that we have the following list of words:

['Mirror', 'Mirror', 'on', 'the', 'wall']

There are 5 words in this list, with the middle word being 'on'. When the length of the list is an odd number, there is exactly one middle word. If the length is even, on the other hand, then there are two middle words. For example, in the case of:

['Baa', 'baa', 'black', 'sheep', 'have', 'you', 'any', 'wool']

the two middle words are 'sheep' and 'have'.

Your task is to write a function middle_words(word_list) that returns the middle word(s) from the non-empty list-of-strings word_list. If the length of word_list is an odd number, you should return a list containing the single middle word; and if the length of word_list is an even number, you should return a list containing the two middle words, in the same order as they occurred in the word_list. For example:

>>> middle_words(['Mirror', 'Mirror', 'on', 'the', 'wall'])
["on"]
>>> middle_words(['Baa', 'baa', 'black', 'sheep', 'have', 'you', 'any', 'wool'])
["sheep", "have"]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!