Skip to content

Commit b6deaa5

Browse files
committed
345
1 parent 533f53e commit b6deaa5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

345vowelreverse.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution(object):
2+
def reverseVowels(self, s):
3+
"""
4+
:type s: str
5+
:rtype: str
6+
"""
7+
s_list = list(s)
8+
vowels_to_reverse = list()
9+
for i in range(len(s_list)):
10+
if s_list[i] in ['a','e','i','o','u','A','E','I','O','U']:
11+
vowels_to_reverse.append(s_list[i])
12+
#index of indices is same as index of vaowels
13+
#use 2 indices on list of indices to reverse
14+
k=1
15+
for i in range(len(s_list)):
16+
if s_list[i] in ['a','e','i','o','u','A','E','I','O','U']:
17+
s_list[i] = vowels_to_reverse[-k]
18+
k+=1
19+
return ''.join(s_list)
20+
21+
class1= Solution()
22+
print(class1.reverseVowels("This is a sentence with flipped vowels"))

0 commit comments

Comments
 (0)