-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeating.py
More file actions
58 lines (44 loc) · 1.45 KB
/
repeating.py
File metadata and controls
58 lines (44 loc) · 1.45 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
VOWELS = "aeiou"
def repeated(s: str) -> bool:
return s in (s + s)[1: -1]
def get_vowel_substrings(s: str) -> list:
if s and s.isalpha():
vowel_indexes: list = []
answer = set()
for index, c in enumerate(s):
if c in VOWELS:
answer.add(c)
vowel_indexes.append(index)
answer = answer.union(index_substrings(vowel_indexes, s))
return sorted(answer)
return []
def get_consonant_substrings(s: str) -> list:
if s and s.isalpha():
consonant_indexes: list = []
answer = set()
for index, c in enumerate(s):
if c not in VOWELS:
answer.add(c)
consonant_indexes.append(index)
answer = answer.union(index_substrings(consonant_indexes, s))
return sorted(answer)
return []
def index_substrings(indexes: list, s: str) -> set:
answer = set()
while len(indexes) > 1:
start = indexes.pop(0)
for index in indexes:
sub_string = s[start:index+1]
answer.add(sub_string)
return answer
if __name__ == "__main__":
print(get_vowel_substrings("apple"))
print(get_vowel_substrings("hmm"))
print(get_consonant_substrings("aviation"))
print(get_consonant_substrings("motor"))
print()
print(repeated("a"))
print(repeated("ababab"))
print(repeated("aba"))
print(repeated("abcabcabcabc"))
print(repeated("aaxxtaaxztaaxxt"))