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 trial

Python Python Collections (Retired) Lists Redux Disemvoweled

douglas gray
douglas gray
888 Points

General technique and a program that won't run.

Hey everyone! My first question is could anyone guess some reasons that my program simply won't run? When I try to run it in the shell it acts as if it is running but no list of vowel free states appears. When I tinker with the above script and re-run it I get error messages I expect, so maybe it is reading it. Could it be that my last two lines-- "output.append....." and "print (output)" aren't arranged correctly? As i understood it they could run outside the while loop, but I tried putting them in it just in case.

Something related that I was wondering about was, how might I understand Pythons treatment of each of the state names in the original name list? I see the program iterates through the vowel list and removes them from the state_list, but why doesn't it need a separate command to iterate through the entire state_list since it's made of many items?

My apologies if any of that is convoluted. This is still foreign to me. Thanks for any insight!

douglas gray
douglas gray
888 Points

i meant, i get error messages, so i know it is reading it.

If you can post your code we might be able to see what is wrong with it.

3 Answers

Steven Parker
Steven Parker
229,582 Points

As the others mentioned, you should post the code you would like specific help with.

But for your other question, the program does not need a loop to iterate through state_list because the remove method will take away the vowels no matter where they are in the list. In a sense, remove is the command you are expecting.

douglas gray
douglas gray
888 Points

Hey there! My code is as follows:

State_names = [California, Florida, Oklahoma] vowels = [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)

I keep getting an error message saying that the states in State_names aren't defined.

douglas gray
douglas gray
888 Points

Of course. Thank you, Steven. Now it prints a list of states but with the vowels still in them. Do you know the best way to share a snapshot of the workspace here in this forum?

You should probably put some quotes or something around your Strings in your State_names list. Maybe do the same with your vowels variable.

I tweaked your code to make it run, I didn't fix any logic errors if any, but here is the code that runs:

State_names = ['California', 'Florida', 'Oklahoma'] 
vowels = ['a','e','i','o','u'] 
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)