Anti_vowel


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/2?curriculum_id=4f89dab3d788890003000096#


Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "Hey lk Wrds!" when it should return "Hy lk Wrds!".


For some reason it doesn't remove the letter 'e' ???


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


#2

That line is unreachable after return. Remove indentation so it is outside of the code block.

When using the str.replace() method, we do not need to iterate the string, only the vowels.

for i in 'aeiouAEIOU':
    text = text.replace(i, '')

We don't even need a conditional. replace is greedy and will remove all that it finds in the string. If not found, it just goes to the next letter in the vowel string.

I recommend staying with this exercise while you devise other ways of removing the vowels than this simple built-in. It teaches us nothing of raw algorithms, which is the real purpose of this exercise.


#3

I have a question, how should we solve this without learning the .replace() function and not learning it in the exercises for beginners?


#4

It may have come up in an exercise, but I suspect it is something that was picked up in the forums. We find it very typical of learners to spread their wings on the forums, which is sometimes okay, to a point, and sometimes not okay, for various reasons.

Once learned and read about we can add it to our toolkit. But it does not preclude bare bones algorithm creation. That is a fundamental component of understanding program architecture and step by step start to finish approaches. We should not discount something just because it is inefficient and not very elegant. There are little tells in every form of program and lots to learn by the extra work we put into them.


#5

I do understand, your exercises are well built and allows the user to learn on a fast pace and offer challenges along the way that guarantees that the user after the course is ready and will be able to expand his knowledge furthermore. And I apologize for commenting earlyt since I just found out this exercise can be completed in many different ways and in the same ways we were taught during the course.


#6

Thanks 'mtf'.
It makes sense and problem solved. Works now with your help.


#7

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