Skip to content

Instantly share code, notes, and snippets.

Last active January 1, 2016 09:09
Show Gist options
  • Save nosada/8123553 to your computer and use it in GitHub Desktop.
Save nosada/8123553 to your computer and use it in GitHub Desktop.
Pig Latin Translator (Only Plain -> PigLatin)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
Translate plain-text English(or ACII string) into Pig Latin
class PigLatin:
vowels = ['a', 'e', 'i', 'o', 'u', 'y']
words = []
scaled_words = []
ordsway = []
def __init__(self, str):
self.words = str.split(' ')
def Translate(self):
"""Translate plain-text into Pig Latin.
Given a prain-text string(str), then translate str into
Pig Latin and return it.
# character scaling
for word in self.words:
# translating into Pig Latin
for word in self.scaled_words:
if word[0][0] not in self.vowels:
ordw = self.Move_1st_syllable_to_tail(word)
self.ordsway.append("".join(ordw) + "ay")
self.ordsway.append("".join(word) + "way")
ingstray = ' '.join(self.ordsway)
return ingstray
def Move_1st_syllable_to_tail(self, word):
"""Move 1st syllable in the word to tail of the word.
Given a word(word), then find out 1st syllable in given word
and move it to tail of the word. Return the result.
i = 0
while word[i] not in self.vowels:
i += 1
return word[i:] + word[0:i]
if __name__ == '__main__':
str = input()
PL = PigLatin(str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment