Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDonald Tam
1,570 PointsDon't use the remove function, the reason being, it only removes the first occurrence in the list
I have checked some post.
known that script below have some problem. solving way have also posted to us.
But sorry that I still do not understand.
as for function , it go for each item in list_word:
so , if list_word = [ 'A', 'A', 'A', 'A'], each 'A' would go though.
I known the fact told me I am false:
disemvowel('AAAAAA')
the outcome would be: ['A', 'A', 'A']
pls help correct my thought
for i in list_word:
if i in list('AEIOUaeiou') :
list_word.remove(i)
print (list_word)
else:
continue
def disemvowel(word):
return word
1 Answer
Juan Castro
11,322 PointsThat's because you are modifying the same list that you are iterating on. You should use a second list where you append the chars that are not vowels, or u could do something like this.
def disemvowel(word):
string = "AEIOUaeiou"
for i in string:
word = word.replace(i, "")
return word
Donald Tam
1,570 PointsDonald Tam
1,570 Pointsthx Juan Castro