DEV Community

Discussion on: Piglatin in python and orgmode.

Collapse
 
pbouillon profile image
Pierre Bouillon

Awesome ! I was curious so I tried to implement it too in my free time, here is my a-little-more-concise solution !

def to_pig_latin(word: str) -> str:
    """convert a word to piglatin

    :param word: word to convert
    :return: the pigralitine version of the word
    """

    if word[0] in 'aeiou':
        complementary = 'way'
    else:
        complementary = f'{word[0]}ay'

    return f'{word[1:]}{complementary}'


if __name__ == '__main__':
    words = [
        'Dog',
        'Nyx',
        'Puppy',
        'Gizmo',
        'Kitten',
        'Luna-fish',
        'Tuna-fish',
        'Apple',
        'Orange',
    ]

    for word in words:
        print(f'{word} is {to_pig_latin(word).title()} in piglatin')
Collapse
 
zeeter profile image
D Smith

Oh thats good! Mine was meant to be entirely run inside this article using orgmode and such. I totally forgot to set it up so that you can tangle the file out.