-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathordered vowels.py
More file actions
26 lines (24 loc) · 880 Bytes
/
ordered vowels.py
File metadata and controls
26 lines (24 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Write a method, `ordered_vowel_words(str)` that takes a string of
# lowercase words and returns a string with just the words containing
# all their vowels (excluding "y") in alphabetical order. Vowels may
# be repeated (`"afoot"` is an ordered vowel word).
#
# You will probably want a helper method, `ordered_vowel_word?(word)`
# which returns true/false if a word's vowels are ordered.
def is_ordered_word(word):
vowels = list('aeiou')
spot = -1
for letter in word:
if letter in vowels:
if vowels.index(letter) >= spot:
spot = vowels.index(letter)
else:
return False
return True
def ordered_voweled_words(input_string):
answer = []
words = input_string.split()
for word in words:
if is_ordered_word(word) == True:
answer.append(word)
return ' '.join(answer)