AntiVowel what's wrong?


#1



I assumed that strings are treated as lists. I would think that i would take each character from the text and match with "aeiouAEIOU" per the hint. Then I would just re-label the....oh ■■■■. I think i know where I went wrong. Nevermind, still don't....


Oops, try again. Does your anti_vowel function take exactly one argument (a string)? Your code threw a "'str' object does not support item assignment" error.


def anti_vowel(text):
    for i in text:
        if i in "aeiouAEIOU":
            text[i] = ''
    return text

#tried again with counter

def anti_vowel(text):
    counter = 0
    for i in text:
        if i in "aeiouAEIOU":
            text[counter] = ''
            counter +=1
        else:
            counter +=1
    return text


#2

I assumed that strings are treated as lists.

Nope,They're different . lists are mutable data type but strings are not.

Reason of error:
(Both of your code examples violates immutability of string thus you're getting an error)
String data type is immutable.

hint**
You need to convert text to list then after you remove vowels ,convert list back to string

Further hint**

x = "Mango"

x[0] =  "J" # this will throw an error.

#3

gah. I feel like i did that before though and it worked...

x = "word"
x[0] = 'L'

or maybe it was
x = ['w', 'o', 'r', 'd']
x[0] = 'L'


#4

It was definitely this..

# or maybe it was 
x = ['w', 'o', 'r', 'd']
x[0] = 'L'

As I mentioned the hint ...
hint**
You need to convert text to list then after you remove vowels ,convert list back to string.

There islist() method that converts string to list.
There is .join() method that converts list back to string.


#5

Lol I think I got it by accident...it works now :joy:

def anti_vowel(text):
    counter = 0
    text_list = list(text)
    for i in text_list:
        if i in "aeiouAEIOU":
            text_list[counter] = ''
            counter +=1
        else:
            counter +=1
    return ''.join(text_list)

#6

That was fast! :thumbsup:


#7

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