如何用Python交换元音和辅音

use*_*535 2 python exchange-server decode

我想创建一个函数,它将按以下方式解码一个单词:第一个元音与最后一个元音交换,第二个元素与倒数第二个交换等.我想用辅音做同样的事情.最后它将返回解码的单词.

这是我的元音代码的开头:

def decode(w):
    for i in range(len(w)):
        for j in range(len(w[::-1])):
            if (i[0] in 'aeiouy' and j[0] in 'aeiouy'):
                s[i],s[j]=s[j],s[i]
    return w
Run Code Online (Sandbox Code Playgroud)

问题是我不知道如何交换这封信.

例如:我给了一个词:'星期六'我的功能给了'dyratsua'回来

For*_*ght 5

word = 'aerodynamic'

vowels = 'aeiouy'

is_vowel = [x in vowels for x in word]
word_vowels = [x for x in word if x in vowels]
word_consonants = [x for x in word if x not in vowels]

word_vowels.reverse()
word_consonants.reverse()

new_word = [word_vowels.pop(0) if x else word_consonants.pop(0) for x in is_vowel]
Run Code Online (Sandbox Code Playgroud)