forked from guillermogut/codeReview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoveVowelsFromString.py
More file actions
65 lines (41 loc) · 1.38 KB
/
removeVowelsFromString.py
File metadata and controls
65 lines (41 loc) · 1.38 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
54
55
56
57
58
59
60
61
62
63
# Given a string s, remove the vowels 'a', 'e', 'i', 'o', and 'u' from it, and return the new string.
#
# 1 <= s.length <= 1000
# s consists of only lowercase English letters.
#
#test cases
testList = [
("a", ""),
("ab", "b"),
("g", "g"),
("aaaaab", "b"),
("bbbbba", "bbbbb"),
("abababa", "bbb")
]
# this problem requires us to modify a string and return it,but python strings are immutable
# a new string may be required for us to skip vowels
#if a char in a string is a vowel, skip it, else put it in the string we want to return
# to make things cleaner, a function that checks whether a char is a vowel is needed
#thoughts on time complexity:
#we must go through the entire array
def isVowel(c)->bool:
vowels = ['a','e','i','o','u']
if c in vowels:
return True
else:
return False
def removeVowels(str1)->str:
noVowels = ""
for x in range(len(str1)):
if isVowel(str1[x]):
continue
else:
noVowels +=str1[x]
return noVowels
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
for (test_in, expected) in testList:
result = removeVowels(test_in)
result_str = "passed" if result == expected else "FAILED"
print(result_str, ' test_in: ', test_in, ' result: ', result)
# See PyCharm help at https://www.jetbrains.com/help/pycharm/