gpt4 book ai didi

Python反元音功能——部分元音无法去除

转载 作者:太空宇宙 更新时间:2023-11-04 08:00:41 24 4
gpt4 key购买 nike

<分区>

我刚开始在 codacademy 学习 Python。我试图做反元音功能,但发现 'u' 有以下问题。

def anti_vowel(text):
a = []
for i in text:
a.append(i)
for item in a:
if item in "aeiouAEIOU":
a.remove(item)
print ''.join(a)

print anti_vowel("Hey You!")
print anti_vowel("Hey look Words!")
print anti_vowel("aeiouAEIOU")

打印出来

"Hy Yu!"
"Hy lk Words!"
"eoAIU"

代替

"Hy Y!"
"Hy lk Wrds!"
""

不知何故,一些元音没有被删除。

我找到了该功能的许多替代方案。但是,请帮我找出当前代码的错误。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com