Skip to content

Instantly share code, notes, and snippets.

@makmac213
Last active April 24, 2020 10:32
Show Gist options
  • Save makmac213/4f8fb5da6c0c9c2ec85016c60b2b29be to your computer and use it in GitHub Desktop.
Save makmac213/4f8fb5da6c0c9c2ec85016c60b2b29be to your computer and use it in GitHub Desktop.
Lodi Petmalu
# wadpata alaws wamaga ):
VOWELS = ["a", "e", "i", "o", "u"]
ADD_S = ["n", "t", "w"]
def syllabicate(word):
# Yorme style syllabication
# TODO: Incomplete find other test cases
word = word.lower()
syllables = []
i = 0
while i < len(word):
if word[i] in VOWELS:
syllables.append(word[i])
i += 1
else:
syllable = word[i]
i += 1
if i < len(word) and word[i] in VOWELS:
syllable += word[i]
i += 1
if i < len(word) and word[i] not in VOWELS and i + 1 == len(word):
syllable += word[i]
i += 1
if i < len(word) and word[i] not in VOWELS and i + 1 == len(word):
syllable += word[i]
i += 1
if i < len(word) and i + 2 == len(word) and word[i + 1] not in VOWELS:
syllable += word[i:]
i += 2
elif syllable == "n" and word[i] == "g":
syllable += word[i]
i += 1
if i < len(word) and word[i] in VOWELS:
syllable += word[i]
i += 1
if i < len(word) and word[i] not in VOWELS and i + 1 == len(word):
syllable += word[i]
i += 1
if i < len(word) and word[i] not in VOWELS and i + 1 == len(word):
syllable += word[i]
i += 1
if i < len(word) and i + 2 == len(word) and word[i + 1] not in VOWELS:
syllable += word[i:]
i += 2
syllables.append(syllable)
return syllables
def tadbalik(word):
ret = ""
word = word.lower()
if len(word) == 4:
ret = word[::-1]
if ret[-1] == "t" and ret[-2] in VOWELS:
ret += "s"
else:
syllables = syllabicate(word)
ret = "".join(syllables[-1]) + "".join(syllables[:-1])
return ret
print(tadbalik("baliktad"))
print(tadbalik("malupet"))
print(tadbalik("pawer"))
print(tadbalik("idol"))
print(tadbalik("pogi"))
print(tadbalik("tama"))
print(tadbalik("pera"))
print(tadbalik("pare"))
print(tadbalik("chibog"))
print(tadbalik("buhok"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment