Anti_vowel How to shorten code?


For the anti_code exercise, my code works, but I would like to shorten the line where I list all of the vowels in the if-statement, as seen below.

def anti_vowel(text):
  new = ""
  for char in text:
    if char=="a" or char=="A" or char=="e" or char=="E" or char=="i" or char=="I" or char=="o" or char=="O" or char=="u" or char=="U":
      new = new + ""
      new = new + char
  print new
  return new

Any help would be appreciated!


The long OR expression can be replaced with in

if char in "aeiouAEIOU":

Compound assignments make for simpler write/read…

new += ""

new += char


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.