Skip to content

Instantly share code, notes, and snippets.

@gamorales
Last active June 5, 2020 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gamorales/007752d3b0a7cc7d6b553cd0ee7c9ddc to your computer and use it in GitHub Desktop.
Save gamorales/007752d3b0a7cc7d6b553cd0ee7c9ddc to your computer and use it in GitHub Desktop.
Rearrange the vowels from a string
def order_vowels_reverse(string):
list_string = [_ for _ in string]
vowels = 'aeiouAEIOU'
vowels_pos = list(filter(lambda car: car in vowels, string))
reverse = vowels_pos[::-1]
index = 0
for car in range(len(list_string)):
if index < len(vowels_pos):
if list_string[car] in vowels_pos[index]:
list_string[car] = reverse[index]
index += 1
return ''.join(list_string)
if __name__ == '__main__':
print(order_vowels_reverse('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris eu mauris nec ex tristique feugiat. Aenean at accumsan tortor. Nulla facilisi. Duis ultrices tellus felis, id tincidunt diam efficitur ut. Suspendisse quis pharetra ante.'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment