How do I find the first occurrence of a vowel and move it behind the original word (pig latin)?
<p>I need to find the first vowel of a string in python, and I'm a beginner. I'm instructed to move the characters before the first vowel to the end of the word and add '-ay'. For example "big" becomes "ig-bay" and "string" becomes "ing-stray" (piglatin, basically).</p>

<p>This is what I have so far:</p>

<pre><code>def convert(s):

    ssplit = s.split()
    beginning = ""
    for char in ssplit:
        if char in ('a','e','i','o','u'):
            end = ssplit[char:]
            strend = str(end)
        else:
            beginning = beginning + char
    return strend + "-" + beginning + "ay"
</code></pre>

<p>I need to find a way to stop the "if" statement from looking for further vowels after finding the first vowel - at least I think it's the problem.  Thanks!</p>

<p>Break things down one step at a time.</p>

<p>Your first task is to find the first vowel. Let's do that:</p>

<pre><code>def first_vowel(s):
    for index, char in enumerate(s):
        if char in 'aeiou':
            return index
    raise Error('No vowel found')
</code></pre>

<p>Then you need to use that first vowel to split your word:</p>

<pre><code>def convert(s):
    index = first_vowel(s)
    return s[index:] + "-" + s[:index] + 'ay'
</code></pre>

<p>Then test it:</p>

<pre><code>print(convert('pig'))
print(convert('string'))
</code></pre>

<p>Full code, runnable, is here: <a href="https://repl.it/Dijj" rel="nofollow">https://repl.it/Dijj</a></p>

<p>The exception handling, for words that have no vowels, is left as an exercise.</p>

python findfirst