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 trialRakesh Bharadwaj
1,376 PointsKindly tell me the mistake. It is giving me proper output
def disemvowel(word): lime = list(word) vowel = ["a","e","i","o","u"] for letter in lime: if letter.lower() in vowel: lime.remove(letter) word = "".join(lime) return word
def disemvowel(word):
lime = list(word)
vowel = ["a","e","i","o","u"]
for letter in lime:
if letter.lower() in vowel:
lime.remove(letter)
word = "".join(lime)
return word
1 Answer
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou are modifying the list that you are looping through. this results in skipping elements in the list. to see it give incorrect output try a word with several vowels in a row, like beauty. the remove method removes the requested element, but the remaining elements shift left by one. the loop then goes to the next element, which means elements get skipped. to solve make a copy of the list and loop through it while modifying the original, or vice versa.
Rakesh Bharadwaj
1,376 PointsRakesh Bharadwaj
1,376 Pointsdef disemvowel(word): lime = list(word) lemon = lime vowel = ["a","e","i","o","u"] #print(lime) for letter in lime: #print(lime) print(lemon) if letter.lower() in vowel: #print(letter.upper()) #print(len(lime)) lemon.remove(letter) #print(len(lime)) word = "".join(lemon) return word
disemvowel("aaaaaa")
print(disemvowel("aaaa"))
I have modified this by copying it to "lemon" list, but i donot understand 2 things here
My concept says that for should loop through every letter in lime. Can you pls help me here