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 trialOprea Mihai
5,592 Pointsdisemvowel_2
Althought in PyCharm it works with both upper and lower case words heer the program doesn't accept it
def disemvowel(word):
word=list(word)
word_c=[]
vocals=['a','e','i','o','u']
for w in word :
if w.lower() in vocals:
word.remove(w)
else:
word_c.append(w)
return"".join(word_c)
1 Answer
Michael Hulet
47,913 PointsIn Python, it's very important that you don't mutate iterables while you iterate over them. Doing so will cause unexpected results, as it throws off the iteration internally. In your case, the problem line is where you run word.remove(w)
. This line mutates the iterable that's being iterated over, and the loop will end up skipping values, and different things will slip through. In your case, you don't actually need to remove the letter, but you just need to continue
onto the next iteration of the loop