为什么删除元音的功能无法正常工作?

时间:2019-03-28 16:23:40

标签: python-2.7

此功能旨在删除字符串中的所有元音,但由于某些原因,它还会删除元音后的字母。

def anti_vowel(text):
  letters = []
  for letter in text:
    letters.append(letter)
  final = ""
  for letter in letters:
    if letter == "A" or letter == "a" or letter == "O" or letter == "o" or letter == "U" or letter == "u" or letter == "I" or letter == "i" or letter == "E" or letter == "e":
      letters.remove(letter)
    else:
      final += letter
  return final

例如,如果您输入“ Hello this is me”,则输出为“ Hlth m”(如果空格位于元音之后,它将删除空格),但是我希望输出为“ Hll ths s m”

0 个答案:

没有答案