Anti_vowel (8)


#1


def anti_vowel(text):
c = ["a","e","i","o","u","A","E","I","O","U"]
a = len(text)
string = []
b = 0
while b < len(text):
string.append(text[b])
print string #for reference. this line is useless
b += 1
else:
for c in string:
string.remove(c)
return "".join(string)

This code does not work. It removes every even numbered index from the list for some reason - i.e. if I had a word 'abcde', I would get back 'bd'.

I managed to make a code that was accepted by the system below, but it seems overly large and honestly, I don't know what I am doing - in particular, what is the difference between the code above and below that makes the one below work but not the one above?

def anti_vowel(text):
d = ["a","e","i","o","u","A","E","I","O","U"]
a = len(text)
string = []
b = 0
while b < len(text):
string.append(text[b])
print string
b += 1
else:
new_word = []
for c in string:
if c not in d:
new_word.append(c)
return "".join(new_word)


#2

remove has a problem. if i would have abcde:

a   b   c   d   e
0   1   2   3   4

strings can't have empty indexes, so if i remove a:

b   c    d   e
0   1    2    3

all the other items will shift. This is why remove is a bad approach to solve this problem.


#3

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