python
Write a function pack_to_5(words) that takes a list ofstring objects as a parameter and returnsa new list containing each stringin the title-case version. Any strings that haveless than 5 characters needs tobe expanded with the appropriate number of space characters to makethem exactly 5 characters long. For example,consider the following list:
words = ['Right', 'SAID', 'jO']
The new list would be:
['Right', 'Said ', 'Jo ']
Since the second element only contains 4 characters, an extraspace must be added to the end. The third element only contains 2characters, so 3 more spaces must be added.
Note:
- Title case means that the first letter of each word isuppercase and the rest lower-case. You may want to use the .title()string function. (e.g. 'SMITH'.title() returns 'Smith')
- You should not modify the original list of string objects.
- You may assume that each word in the list does not have morethan 5 characters.
- You may want to use the format string: '{:<5}' in thisquestion.
For example:
Test | Result |
---|
words = ['Right', 'SAID', 'jO']result = pack_to_5(words)print(words)print(result) | ['Right', 'SAID', 'jO']['Right', 'Said ', 'Jo '] |
words = ['help', 'SAID', 'jO', 'FUNNY']result = pack_to_5(words)print(words)print(result) | ['help', 'SAID', 'jO', 'FUNNY']['Help ', 'Said ', 'Jo ', 'Funny'] |
result = pack_to_5([])print(result) | [] |