How to transforms words to pig latin and remove the last consonant and vowel of the word if they exist

My output is empty :frowning:

def pig_latin(txt):
    vowels = ['a', 'e', 'i', 'u', 'o', 'y']
    consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'z']
    consonant_ending = []
    vowel_ending = []
    txt = txt.split()
    for word in txt:
        if word[-1] in vowels:
            vowel_ending.append(word[:-1])
        else:
            consonant_ending.append(word[:-1])
    for idx, word in enumerate(vowel_ending):
        vowel_ending[idx] = word[-1]
    for idx, word in enumerate(consonant_ending):
        consonant_ending[idx] = word[-1]
    for idx, word in enumerate(consonant_ending):
        if word in vowels:
            consonant_ending[idx] = word[:-1]
    for idx, word in enumerate(consonant_ending):
        if word not in vowels:
            consonant_ending[idx] = word
    result = ''
    for idx, word in enumerate(consonant_ending):
        result += consonant_ending[idx]
    return result

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

You are doing a lot of looping here, loosing the actual order of words in the sentence AND never include the “vowel_ending” in the result anyway. Soooo whatever you are doing here needs to be redone completly.
Plus I have trouble understanding what you are doing here. Appearently you are replacing the “consonant_ending” words with just the last letter and then check if that is a vowel?