What do we get if we reverse the vowels of a word or a sentence, maintaining the original capitalization of the vowels? The word multiMILLIONAIRE becomes meltiMALLOINIIRU.
The catchphrase
And now for something completely different.
that featured in every episode of the surreal sketch comedy series Monty Python's Flying Circus1 becomes
End new fir semethong cimpletoly dofforant.
This comes horribly close to the way some BBC2 presenters pronounced this phrase that has long been a standard way of transitioning between unrelated topics. It's origin is credited to Christopher Trace3, founding presenter of the BBC children's television programme Blue Peter4, who used it (in all seriousness) as a link between segments. Now you know where the Monty Python group got its inspiration.
Reverse the vowels of a word or a sentence, while maintaining the original capitalization of the vowels. The vowels are the letters a, e, i, o and u. This is done in the following way:
Write a function vowels that takes a string $$s$$ (str). The function must return the string (str) containing all vowels from $$s$$. In other words: the result after discarding all characters from $$s$$ that aren't vowels.
Write a function vowel_from_left that takes two arguments: i) a string $$s$$ (str) and ii) a number $$n \in \mathbb{N}_0$$ (int). The function must return the $$n$$-th vowel from $$s$$, where vowels are counted from left to right (starting at 1). The function may assume that $$s$$ contains at least $$n$$ vowels, without the need to check this explicitly.
Write a function vowel_from_right that takes two arguments: i) a string $$s$$ (str) and ii) a number $$n \in \mathbb{N}_0$$ (int). The function must return the $$n$$-th vowel from $$s$$, where vowels are counted from right to left (starting at 1). The function may assume that $$s$$ contains at least $$n$$ vowels, without the need to check this explicitly.
Write a function reversed_vowels that takes a string $$s$$ (str). The function must reverse the order of the vowels in $$s$$, maintaining the original capitalization of the vowels. The result (str) must be returned by the function.
These functions may not make a distinction between uppercase and lowercase letters when determining if a character is a vowel.
>>> vowels('multiMILLIONAIRE')
'uiIIOAIE'
>>> vowels('And now for something completely different.')
'Aoooeioeeiee'
>>> vowel_from_left('multiMILLIONAIRE', 5)
'O'
>>> vowel_from_left('And now for something completely different.', 1)
'A'
>>> vowel_from_right('multiMILLIONAIRE', 3)
'A'
>>> vowel_from_right('And now for something completely different.', 1)
'e'
>>> reversed_vowels('multiMILLIONAIRE')
'meltiMALLOINIIRU'
>>> reversed_vowels('And now for something completely different.')
'End new fir semethong cimpletoly dofforant.'