Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # wadpata alaws wamaga ):
- VOWELS = ["a", "e", "i", "o", "u"]
- ADD_S = ["n", "t", "w"]
- def syllabicate(word):
- # Filipino 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"))
Add Comment
Please, Sign In to add comment