8.15 Simpler Way to do This?


#1

This code here worked just fine:

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

I was just curious though, is there an easier/cleaner way to do this?


#2

Sure,

from re import sub
def anti_vowel(text):
    return sub('[aeiouAEIOU]', '', text)

or

def anti_vowel(text):
    return ''.join((letter for letter in text if letter not in 'aeiouAEIOU'))

Easy enough.


#3

You are a wizard, my friend.


#4

it"s simple cool..but i dont understand what that does...could you please explain me that stuff??