Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

For loop only giving one item in list

Not sure why I am only getting one part from my computer_parts list.

computer_parts = ['motherBoard', 'processor', 'graphicsard']
vowels = list('aeiou')
output = []

for parts in computer_parts: #breaking down the list 
    parts_list = list(parts.lower())
    #removing vowels by seperating the inital list into a list of letterss
    for vowel in vowels:
        while True:
            try:
                parts_list.remove(vowel) 
            except:
                break
#joining words inside of spaces and capatilizing first letter
output.append(''.join(parts_list).capitalize()) 

print(output)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,986 Points

Your join and append to output needs to be indented one stop. It is currently executed once after both for loop complete.

I gotcha, it needs to run inside the for loop.