-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplacevowels.py
More file actions
53 lines (36 loc) · 1.1 KB
/
replacevowels.py
File metadata and controls
53 lines (36 loc) · 1.1 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Given list of chars, return a new copy, but with vowels replaced by '*'.
For example::
>>> replace_vowels(['h', 'i'])
['h', '*']
>>> replace_vowels([])
[]
>>> replace_vowels(['o', 'o', 'o'])
['*', '*', '*']
>>> replace_vowels(['z', 'z', 'z'])
['z', 'z', 'z']
Make sure to handle uppercase::
>>> replace_vowels(["A", "b"])
['*', 'b']
Do not consider `y` a vowel::
>>> replace_vowels(["y", "a", "y"])
['y', '*', 'y']
This should return a new list, not mutate the original::
>>> a = ['h', 'i']
>>> out = replace_vowels(a)
"""
def replace_vowels(chars):
"""Given list of chars, return a new copy, but with vowels replaced by '*'."""
no_vowels = []
vowels = set(['a', 'e', 'i', 'o', 'u'])
for char in chars:
if char in vowels:
no_vowels.append("*")
elif char.lower() in vowels:
no_vowels.append("*")
else:
no_vowels.append(char)
return no_vowels
if __name__ == '__main__':
import doctest
if doctest.testmod().failed == 0:
print "\n*** ALL TESTS PASSED. YAY!\n"