8/15 my solution to anti_vowel


I thought it would be easiest to incorporate a list as part of the solution. Below is the code:

 def anti_vowel(text):
        anti = ""
        vowels = ['A','E','I','O','U','a','e','i','o','u']
        for char in text:
            if char not in vowels:
                anti = anti + char
        return anti


Looks good, while you can search for both capital and lower case you can just make them all lower case when you import the text with the lower() builtin string method.

word = 'WORD'
l_word = word.lower()

Also you are correct using a list is a good way to do this but you can also do it like this.

word = 'WORD'
 def anti_vowel(text):
        anti = ""
        for char in text.lower():
            if char not in 'aeiou':
                anti += char
        return anti

Note that there is nothing wrong with your code just as you get better you would not repeat using code or make containers to hold data if you don't need to.

Also here is a one liner for you to look at.

def anti_vowel(text):
    return ''.join([letter for letter in list(text.lower()) if letter not in 'aeiou'])


awesome, thanks for the feedback!


Here was my solution, though a little longer than some of the above. I new to the course and I was not aware of the ' not in' approach.

def anti_vowel(text):
    wrd = ""
    for letter in text:
        if letter.lower() == "a" \
        or letter.lower() == "e" \
        or letter.lower() == "i" \
        or letter.lower() == "o" \
        or letter.lower() == "u":
            wrd = wrd
            wrd = wrd + letter
    return wrd

I also tried the alternative approach above and found that the following from YahooSMith works if you put the .lower() within the if statement:

word = 'WORD'
def anti_vowel(text):
        anti = ""
        for char in text:
            if char.lower() not in 'aeiou':  # added .lower() here
                anti += char
        return anti

Learned a lot on this exercise. Thanks to all.

def anti_vowel(text):
    x = ""
    for i in text:
        if i not in "aeiouAEIOU":
            x = x + i
    return x


Is there a way to remove every vowel in the text?
I see your solution is to add up every item that is NOT vowel. It's brilliant.

My original method was to remove every vowel in the text. And I failed to get the correct answer.


Your simple solution to this problem makes me want to give up programming. Only when I see other people's code does the the "Ahhh. I get it" moment ever occur. Thanks for the solution!


My solution

def anti_vowel(text):

for t in range(0,len(text)):
    if text[t] not in vowel:

return "".join(newList)

print anti_vowel("Hey You!")


A bit lengthy, but it gets the job done. Here is my solution:

# remove all vowels from a given text:
def anti_vowel(text):
    text = str (text)
    newstr = ""
    for letter in text:
        if letter in "aeiouAEIOU":
            newstr = newstr + ""
            newstr = newstr + letter
        return newstr
print anti_vowel ("abelone")

def anti_vowel(text):
    no_vowel = ""
    for char in text:
        if char.lower() not in "aeiou":
            no_vowel += char
    return no_vowel


Try this

def anti_vowel(text):
item = "aeiouAEIOU"
for i in text:
for x in item:
if i == x:
text = text.replace(i,"")
return text

def anti_vowel(text):
    vowels = 'aouei'
    return ''.join(a for a in text if a.lower() not in vowels)


I feel so stupid when I saw you guys' solutions. Here's mine:

def anti_vowel(text):
i = 0
s = ''
while i < len(text):
    n = 0
    for c in "AEIOUaeiou":
        if text[i] != c:
            n += 1
    if n == 10:
        s += text[i]
    i += 1
return s


I was looking for the simplest solution and your code helped out a lot. Thanks erikvec.


I am a noob.... I liked your method, however had to move the .lower for it to work.

def anti_vowel(text):
    voweless = ""
    for x in text:
        if x.lower() not in 'aeiou':
            voweless += x
    return voweless


While my solution is clearly not the most elegant, I can't figure out why it doesn't work. Error message states that it returns "Hy lk Words!" when it should return "Hy lk Wrds!". Not sure why it's only reaching the first two Os. Any suggestions?

def anti_vowel(text):
    text_list = []
    for each in text:
    for item in text_list:
        if item.lower() == "o" or item.lower() == "e" or item.lower() == "i" or item.lower() == "u":
    return "".join(text_list)


I didn't see a reply to your question, so apologies if you already got a solution for removing vowels. Here is mine.

def anti_vowel(text):
    vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']     #list of the vowels
    text_to_list = list(text)   #makes the input string into a list
    for i in text:  #iterating through the initial string
        for v in vowels:    #iterating through the list of vowels
            if i == v:  #checking whether there are any vowels in the string
                text_to_list.remove(i)  #removing the vowels from the list
    return "".join(text_to_list)    #reformating the list back into string and joining the items

word = raw_input("Enter your text: ")   #allowing the user to input text
print ("Your text without the vowels: %s") % anti_vowel(word)   #returning the text without the vowels


The hint is also helpful, giving some code that can save some coding;

To check to see if c is a vowel, you can do: c in "aeiouAEIOU".


what's wrong in my code??

def anti_vowel(text):
for char in text:
if ch=="a" or ch="e" or ch="i" or ch="o" ch="u":
return ""
return ch


hey zeziba, could you explain how the one line works please?