-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path824_GoatLatin.py
More file actions
27 lines (23 loc) · 918 Bytes
/
824_GoatLatin.py
File metadata and controls
27 lines (23 loc) · 918 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
27
class Solution:
def toGoatLatin(self, S: str) -> str:
sentences = S.split(' ')
vowels = 'AEIOUaeiou'
ans = []
for index,word in enumerate(sentences):
if word[0] in vowels:
ans.append(sentences[index]+'ma')
else:
ans.append(sentences[index][1:]+sentences[index][0]+'ma')
ans[index] = ans[index]+('a'*(index+1))
return " ".join(i for i in ans)
def main():
ret = Solution().toGoatLatin("I speak Goat Latin")
out = (ret)
print(out)
# Output: "Imaa peaksmaaa oatGmaaaa atinLmaaaaa"
ret = Solution().toGoatLatin("The quick brown fox jumped over the lazy dog")
out = (ret)
print(out)
# Output: "heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa"
if __name__ == '__main__':
main()