aboutsummaryrefslogtreecommitdiff
path: root/challenge-254/sgreen/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-254/sgreen/python/ch-2.py')
-rwxr-xr-xchallenge-254/sgreen/python/ch-2.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-254/sgreen/python/ch-2.py b/challenge-254/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..eed9768157
--- /dev/null
+++ b/challenge-254/sgreen/python/ch-2.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def reverse_vowels(s: str) -> str:
+ # Convert it to lower case
+ s = s.lower()
+
+ # Extract the vowels
+ vowel_list = [c for c in s if c in 'aeiou']
+
+ new_string = ''
+ for c in s:
+ # If the character here is a vowel
+ if c in 'aeiou':
+ # ... get the last vowel
+ new_string += vowel_list.pop()
+ else:
+ new_string += c
+
+ return new_string.capitalize()
+
+
+def main():
+ s = sys.argv[1]
+ print(reverse_vowels(s))
+
+
+if __name__ == '__main__':
+ main()