Guest User

Untitled

a guest
Nov 20th, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. # wadpata alaws wamaga ):
  2.  
  3. VOWELS = ["a", "e", "i", "o", "u"]
  4.  
  5. ADD_S = ["n", "t", "w"]
  6.  
  7. def syllabicate(word):
  8. # Filipino style syllabication
  9. # TODO: Incomplete find other test cases
  10. word = word.lower()
  11. syllables = []
  12. i = 0
  13. while i < len(word):
  14. if word[i] in VOWELS:
  15. syllables.append(word[i])
  16. i += 1
  17. else:
  18. syllable = word[i]
  19. i += 1
  20. if i < len(word) and word[i] in VOWELS:
  21. syllable += word[i]
  22. i += 1
  23. if i < len(word) and word[i] not in VOWELS and i + 1 == len(word):
  24. syllable += word[i]
  25. i += 1
  26. if i < len(word) and word[i] not in VOWELS and i + 1 == len(word):
  27. syllable += word[i]
  28. i += 1
  29. if i < len(word) and i + 2 == len(word) and word[i + 1] not in VOWELS:
  30. syllable += word[i:]
  31. i += 2
  32. elif syllable == "n" and word[i] == "g":
  33. syllable += word[i]
  34. i += 1
  35. if i < len(word) and word[i] in VOWELS:
  36. syllable += word[i]
  37. i += 1
  38. if i < len(word) and word[i] not in VOWELS and i + 1 == len(word):
  39. syllable += word[i]
  40. i += 1
  41. if i < len(word) and word[i] not in VOWELS and i + 1 == len(word):
  42. syllable += word[i]
  43. i += 1
  44. if i < len(word) and i + 2 == len(word) and word[i + 1] not in VOWELS:
  45. syllable += word[i:]
  46. i += 2
  47. syllables.append(syllable)
  48. return syllables
  49.  
  50.  
  51. def tadbalik(word):
  52. ret = ""
  53. word = word.lower()
  54. if len(word) == 4:
  55. ret = word[::-1]
  56. if ret[-1] == "t" and ret[-2] in VOWELS:
  57. ret += "s"
  58. else:
  59. syllables = syllabicate(word)
  60. ret = "".join(syllables[-1]) + "".join(syllables[:-1])
  61. return ret
  62.  
  63.  
  64. print(tadbalik("baliktad"))
  65. print(tadbalik("malupet"))
  66. print(tadbalik("pawer"))
  67. print(tadbalik("idol"))
  68. print(tadbalik("pogi"))
  69. print(tadbalik("tama"))
  70. print(tadbalik("pera"))
  71. print(tadbalik("pare"))
  72. print(tadbalik("chibog"))
  73. print(tadbalik("buhok"))
Add Comment
Please, Sign In to add comment