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 trialKayla Johhnson
756 Pointsdisemvowel
Ok, so i finally figured this out for the most part. For one, I was confusing the methods .upper and .lower = I figured you use upper (when you have provided lower case vowels) to catch any upper case vowels passed through. But actually you use .lower (if you have, indeed provided lower case vowels in your list of vowels) to coerce any letters passed through to lower case so that they are caught.
I needed to communicate that so that it will sink in.
What I don't get: when you use the For Loop why do you need to use a copy of the list or the word itself versus just using the list form of the word?
Why do these work:
for letter in letters.copy() for letter in word
But this doesn't:
for letter in letters
def disemvowel(word):
vowels = ["a" , "e" , "i" , "o" , "u"]
letters = list(word)
for letter in letters:
if letter.lower() in vowels:
letters.remove(letter)
word = "".join(letters)
return word
1 Answer
Steven Parker
231,269 PointsIf you alter an interable while it is controlling a loop, you throw off the internal mechanisms of the loop and cause items to be skipped over.
But if you use a copy of the iterable to control the loop, you can make changes safely.