Last active
June 5, 2020 21:11
-
-
Save gamorales/007752d3b0a7cc7d6b553cd0ee7c9ddc to your computer and use it in GitHub Desktop.
Rearrange the vowels from a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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