Anti_vowel


#1



Below is my code. The problem is that when I tested it using "Hey look Words! ", it prints Hy lk Words!

Why is the last letter "o" is still there?


def anti_vowel(text):
    string=[]
    for letters in text:
        string.append(letters)
    print string
    for each in string:
        if each in "aeiouAEIOU":
            string.remove(each)
    print "".join(string)  
    
anti_vowel("Hey look Words!")


#2

In programming and alot of other things Simplicity is Genius! having said that you can simplify your code a great deal by only using on for loop and not two and since you are dealing with strings it would be easier to use an empty string,

Here's a detailed exampled, let's say I wanted to create a function that filters all the numbers in a sentence it would look something like,

def anti_numbers(text):
    ant = ""
    for i in text:
        if i not in " 123456789":
            ant += i
    return ant
    
print(anti_numbers("I am 15 years old"))

#3

Thank you. Your code is certainly much better than mine.


#4

No code is really "better" the difference between mine is I just knew what I wanted to achieve and did it in thesimplest way possible. :slight_smile:


#5

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