Pig Latin is an English language game where the goal is to hide the meaning of a word from people not aware of the rules.

So, the goal of this kata is to wite a function that encodes a single word string to pig latin.

The rules themselves are rather easy:

1) The word starts with a vowel(a,e,i,o,u) -> return the original string plus "way".

2) The word starts with a consonant -> move consonants from the beginning of the word to the end of the word until the first vowel, then return it plus "ay".

3) The result must be lowercase, regardless of the case of the input. If the input string has any non-alpha characters, the function must return None, null, Nothing (depending on the language).

4) The function must also handle simple random strings and not just English words.

5) The input string has no vowels -> return the original string plus "ay".

For example, the word "spaghetti" becomes "aghettispay" because the first two letters ("sp") are consonants, so they are moved to the end of the string and "ay" is appended.

Difficulty: introductory

Starter code:

def pig_latin(s):
	

Solutions:
VOWELS = set('aeiou')

def pig_latin(st):
    s = st.lower()
    if s.isalpha():
        if set(s) & VOWELS:
            if s[0] in VOWELS:
                s += 'w'
            while s[0] not in VOWELS:
                s = s[1:] + s[:1]
        return s + 'ay'

def pig_latin(s):
    vowels = ['a', 'e', 'i', 'o', 'u']
    word = s.lower()
    if not word.isalpha():    # Check for non alpha character
        return None
    if word[0] in vowels:     # Check if word starts with a vowel
        return word + 'way'
    for i, letter in enumerate(word):    # Find the first vowel and add the beginning to the end 
        if letter in vowels:
            return word[i:]+word[:i]+'ay'
    return word + 'ay'    # No vowels

import re
def pig_latin(s):
    s = s.lower()
    if re.findall('[\d\W]',s) or s == '':
        return None
    elif s.startswith(('a','e','i','o','u')):
        return s + 'way'
    else:
        return re.sub('(^[^aeiou]+)(\w*)','\g<2>\g<1>ay',s)

def pig_latin(s):
    if s.isalpha():
        s = s.lower()
        if s[0] in 'aeiou':
            return s + 'way'
        for i in range(len(s)):
            s = s[1:] + s[0]
            if s[0] in 'aeiou':
                break
        return s + 'ay'
        


def pig_latin(s):
    if not s.isalpha(): return None
    s  = s.lower()
    iV = next((i for i,c in enumerate(s) if c in "aeiou"), len(s))
    return s[iV:] + (s[:iV] or 'w') + "ay"

def pig_latin(s):
    prev, s = '', s.lower()
    if any(ord(x)not in range(ord('a'),ord('z')+1) for x in s) or not s: return
    while s and s[0] not in 'aeiou':
        prev += s[0]
        s = s[1:]
    return f'{s}{prev}{("", "w")[not prev]}ay'

def pig_latin(s):
    a = ''
    if not s.isalpha(): return None
    s = s.lower()
    for i in s:
        if i in 'aeiou':
            break
        a+= i
    return s + 'way' if s[0] in 'aeiou' else s[len(a):] + a + 'ay'

def pig_latin(s):
    if not s.isalpha():
        return None
    s = s.lower()
    if s.startswith(('a', 'e', 'i', 'o', 'u')):
        s += 'w'
        i = 0
    else:
        i = next((i for i, c in enumerate(s) if c in 'aeiou'), 0)
    return s[i:] + s[:i] + 'ay'


def pig_latin(s):
    if not s.isalpha(): return None
    s =s.lower()
    if s[0] in 'aeiou': return s+'way'
    for n,i in enumerate(s):
        if i in 'aeiou':
            return s[n:]+s[0:n]+'ay'
    return s+'ay'