Apply prefix¶
Save these functions into a file named apply_prefix.py.
1. Write function apply_prefix_pure() that takes a
list of words (str) and a prefix (str), and
returns a new list. This output list will contain the same words
as the input one and in the same order, but all the words will begin with
the given prefix, with its first letter capitalised, and followed by
a hyphen. Examples:
>>> lw1 = ['communication', 'medicine', 'vision', 'phone'] >>> res1 = apply_prefix_pure (lw1, 'tele') >>> lw1 ['communication', 'medicine', 'vision', 'phone'] >>> res1 ['Tele-communication', 'Tele-medicine', 'Tele-vision', 'Tele-phone'] >>> lw2 = ['script', 'operative', 'date'] >>> res2 = apply_prefix_pure (lw2, 'post') >>> lw2 ['script', 'operative', 'date'] >>> res2 ['Post-script', 'Post-operative', 'Post-date']Note
More tests are provided in file
test-prefix_pure.txt
2. Write a modifier function apply_prefix_modifier() that
takes a list of words (str) and a prefix
(str), and modifies the given list in such a way that
each word begins with the given prefix, with its first letter
capitalised, and followed by a hyphen. Examples
>>> lw1 = ['communication', 'medicine', 'vision', 'phone'] >>> res1 = apply_prefix_modifier (lw1, 'tele') >>> lw1 ['Tele-communication', 'Tele-medicine', 'Tele-vision', 'Tele-phone'] >>> print(res1) None >>> lw2 = ['script', 'operative', 'date'] >>> res2 = apply_prefix_modifier (lw2, 'post') >>> lw2 ['Post-script', 'Post-operative', 'Post-date'] >>> print(res2) NoneNote
More tests are provided in file
test-prefix_modifier.txtfile.
Solutions
A solution of these functions is provided in file
apply_prefix.py