Revorse the vewels def reverse_vowels(text): Given a text string, create and return a new string constructed by finding all its vowels (for simplicity, in this problem vowels are the letters found in the string 'aeiouAEIOU') and reversing their order, while keeping all other characters exactly as they were in their original positions. However, to make the result look prettier, the capitalization of each moved vowel must be the same as that of the vowel that was originally in the target position. For example, reversing the vowels of 'Ilkka' should produce 'Alkki' instead of 'alkkI'. Applying this operation to random English sentences seems to occasionally give them a curious pseudo-Mediterranean vibe. Along with many possible other ways to perform this square dance, one straightforward way to reverse the vowels starts with collecting all vowels of text into a separate list, and initializing the result to an empty string. After that, iterate through all positions of the original text. Whenever the current position contains a vowel, take one from the end of the list of the vowels. Convert that vowel to either upper- or lowercase depending on the case of the vowel that was originally in that position, and append it to result. Otherwise, append the character from the same position of the original text to the result as it were. text Expected result 'Revorse the vewels' 'Reverse the vowels' 'Ilkka Markus Kokkarinen' 'Elkki Markos Kukkaranin' 'Hello world' 'Hollo werld' 'abcdefghijklmnopqrstuvwxyz' 'ubcdofghijklmnepqrstavwxyz' 'This is Computer Science I!' 'This es Cempiter Scuonci I!'

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 12RQ
icon
Related questions
Question

Revorse the vewels

def reverse_vowels(text):

Given a text string, create and return a new string constructed by finding all its vowels (for simplicity, in this problem vowels are the letters found in the string 'aeiouAEIOU') and reversing their order, while keeping all other characters exactly as they were in their original positions. However, to make the result look prettier, the capitalization of each moved vowel must be the same as that of the vowel that was originally in the target position. For example, reversing the vowels of 'Ilkka' should produce 'Alkki' instead of 'alkkI'. Applying this operation to random English sentences seems to occasionally give them a curious pseudo-Mediterranean vibe.
Along with many possible other ways to perform this square dance, one straightforward way to reverse the vowels starts with collecting all vowels of text into a separate list, and initializing the result to an empty string. After that, iterate through all positions of the original text. Whenever the current position contains a vowel, take one from the end of the list of the vowels. Convert that vowel to either upper- or lowercase depending on the case of the vowel that was originally in that position, and append it to result. Otherwise, append the character from the same position of the original text to the result as it were.

text Expected result
'Revorse the vewels' 'Reverse the vowels'
'Ilkka Markus Kokkarinen' 'Elkki Markos Kukkaranin'
'Hello world' 'Hollo werld'
'abcdefghijklmnopqrstuvwxyz' 'ubcdofghijklmnepqrstavwxyz'
'This is Computer Science I!' 'This es Cempiter Scuonci I!'
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,