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 trialAli AlRabeah
909 PointsRemove vowel function. Why isn't my code working?
The logic is there it seems. Every time it returns the word I get back the same original string. Any help appreciated.
def disemvowel(word):
vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
for letter in word:
if letter in vowels:
del letter
return word
2 Answers
Ines Fazlić
Python Web Development Techdegree Student 9,569 PointsHello Ali, the thing is that word is essentially a string and strings are immutable. So try creating another string that is the initial word without the vowels, and then return it.
Ines Fazlić
Python Web Development Techdegree Student 9,569 PointsHey, I just ment that you can't change the given string, by telling you to make another string I ment to do a list remove vowels and join it into a new string, but I just wanted to give you a hint and not the whole answer so you figure it out.
The first code would work if you had put: for letter in word_list.copy ():
we add the .copy() because when you modify the list while looping through it you can get weird results and it kinda misbehaves :) so we use a copy of the list and for every item from the copy we remove that item from the original list :)
I hope this helps
Ali AlRabeah
909 PointsI have to remember to use copies instead. Appreciate it.
Ali AlRabeah
909 PointsAli AlRabeah
909 PointsI've completed the challenge but in a different way. Every time I ran:
It would only remove some of the vowels it detected. I'm still not sure why. For example: disemvowel("UECwoe") Would return as "ECwe"
So I figured it needed to run through all the vowels so I put a for loop for the vowels.
Do you know why the first one wouldn't work and the second one did? Also, could you elaborate on what you mean by creating another string? Where would it be placed?