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 trialShadow Skillz
3,020 PointsSame script different output?
Created the script(to my knowledge) as the tutorial but when i run the program instead of giving me one list minus the vowels it gives me a list that icramentaly removes the vowels giving variation of the words its working on until done, not to sure what I'm missing.
state_names = ["Alabama", "California","Oklahoma","Florida"]
vowels = list('aeiou')
output = []
for state in state_names:
state_list = list(state.lower())
for vowel in vowels:
while True:
try:
state_list.remove(vowel)
except:
break
output.append(''.join(state_list).capitalize())
print(output)
the result is this
['Lbm', 'Lbm', 'Lbm', 'Lbm', 'Lbm', 'Cliforni', 'Cliforni', 'Clforn', 'Clfrn', 'Clfrn', 'Oklhom', 'Oklhom', 'Oklhom', 'Klhm', 'Kl hm', 'Florid', 'Florid', 'Flord', 'Flrd', 'Flrd']
3 Answers
Nicholas Lim
Python Development Techdegree Student 6,055 PointsHi Christian,
I found the issue in your code, you are correct the code is mostly right and is exactly like the solution, however you made a spacing mistake. These mistakes are common in python I have to watch out for them myself. In your code:
output.append(''.join(state_list).capitalize())
It is under the while true, when should be under for vowel in vowels:, so your output.append is being executed too many times because it's under the while True section instead of for vowel in vowels:
To fix this all you need to do is go to the beginning of the output.append statement and delete one tab space so that it lines up with for vowel in vowels: part of the code, then your answer will look exactly like the tutorial's solution. For example:
def main():
state_names = ["Alabama","California","Oklahoma","Florida"]
vowels = list("aeiou")
output = []
for state in state_names:
state_list = list(state.lower())
for vowel in vowels:
while True:
try:
state_list.remove(vowel)
except:
break
output.append("".join(state_list).capitalize())
print(output)
main()
Kevin Li
2,634 PointsI think you need to unindent the output.append line, so that it matches the 'break' line. Without that indent, the word will get appended every time a vowel is removed, which is why there is a lot of repeats in your final list.
Shadow Skillz
3,020 PointsKev thanks for helping too i need all i can get bro i appreciate it ;-)
Vittorio Somaschini
33,371 PointsHello Christian.
I have edited your question so that it matches these guidelines, please have a read: https://teamtreehouse.com/forum/posting-code-to-the-forum
Getting to your question: Are you sure the code is the same? First thing I have noticed for example is that the indentation of the line starting with output.append does not match the indentation of the video's code.
That could be a starting point to debug the code...
;)
Let me know if you need more help!
Vittorio
Shadow Skillz
3,020 PointsThanks for the help Vittorio really appreciate it. These eye's decieve me every now and then ;-)
Kevin Li
2,634 PointsKevin Li
2,634 PointsYeah, my answer was wrong. Whoops! Look like learning JavaScript mixed up my Python knowledge.
Shadow Skillz
3,020 PointsShadow Skillz
3,020 PointsThanks for the help Nicholas ;-)