15.8 anti_vowel - Why won't my code work?


def anti_vowel(text):
for i in a:
    if i in 'aeiouAEIOU':
for i in text:
    emp = emp + str(i)


This is my code. I know a workaround and I know how to make it work. I just wanted to know why this does not work!


The error message is pointing to this line.The copy() method does not exist for lists.


But this perfectly works on IDLE. And help(list) does show a list.copy() in IDLE.


Firstly there are different versions of python, second not all implementations have the same build in methods.

If you want cross platform you need to have the packages and then export them in your distribution. The course can be any of the 2.7 series of python, also some of the builtins are blocked from use.

Personally I would just use the regex module for this.

from re import sub
def anti_vowel(input_):
    return sub(r"[aeiouAEIOU]", '', input_)

The above takes an argument, then it takes what it will replace it with, and finally the string to work on.

The letters in the bracket means that for each item of any of them match the bracketed items it will sub that position.


I did not know that! Thanks a lot! :smile: