-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubaruba.py
67 lines (54 loc) · 1.93 KB
/
subaruba.py
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
64
65
66
67
import sys
def process_text_ubbi_dubbi(text: str, vowel_list: set, mode: str) -> str:
"""Process the string of text to convert to Ubbi Dubbi language or vice versa.
Args:
text (str): string of text to be processed (may or may not contain vowels)
vowel_list (set): aeiouyAEIOUY
mode (str): 'D' for English to Ubbi Dubbi, 'A' for Ubbi Dubbi to English
Returns:
str: processed text
"""
output = []
if mode == "D":
for i in text:
if i in vowel_list and i.islower():
output.append("ub" + i)
elif i in vowel_list and i.isupper():
output.append("Ub" + i.lower())
else:
output.append(i)
elif mode == "A":
i = 0
while i < len(text):
if (
i + 2 < len(text)
and text[i : i + 2] in {"ub", "Ub"}
and text[i + 2] in vowel_list
):
if text[i : i + 2] == "ub":
output.append(text[i + 2])
elif text[i : i + 2] == "Ub":
output.append(text[i + 2].upper())
i += 3
else:
output.append(text[i])
i += 1
return "".join(output)
def process_text_list_ubbi_dubbi(
lst: list[str],
mode: str,
) -> None:
"""Loop through the list of text to process each string of text.
Args:
lst (list[str]): list of text to be processed
mode (str): 'D' for English to Ubbi Dubbi, 'A' for Ubbi Dubbi to English
"""
for i in lst:
print(process_text_ubbi_dubbi(i, vowel_list, mode))
if __name__ == "__main__":
input_message = sys.stdin.readlines()
mode = input_message[0].strip()
line_number = int(input_message[1].strip())
text_list = [line.strip() for line in input_message[2:]]
vowel_list = set("aeiouyAEIOUY")
process_text_list_ubbi_dubbi(text_list, mode)