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 trialNitesh venkatesh
474 PointsWhats could be wrong with my code here
vowels = ['aeiou']
def a(lister): for state in lister : for letter in vowels : try: while True : print ("enetred while loop") lister.remove(letter) print("{}" % (lister)) continue except : return list
states = [ "california" ] new_list = a(states)
2 Answers
Ira Bradley
12,976 Pointsvowels = ['aeiou']
def a(lister):
for state in lister:
for letter in vowels :
try:
while True :
print ("entered while loop")
lister.remove(letter)
print("{}" % (lister))
continue
except :
return list
states = [ "california" ]
new_list = a(states)
You will get better responses if you properly format your code and link to the challenge. I'm not sure exactly what you are trying to accomplish here but the line lister.remove(letter)
is attempting to remove all the vowels from the item in your states list at once. This won't remove any letters as the string needs to exactly match.
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Nitesh
Looks like you are trying to remove the vowels from each state. Couple of things 1) Don't use a while loop like that where the program has no means to exit. 2) the way your code is right now you have one word in a list called 'aeiou' rather than splitting out the letters like this 'aeiou'.split() which will give you a list like so ['a','e','i','o','u'], which you can than loop around. The way i approach this is that vowels wont change they will always be a,e,i,o,u hence you can do a check for the vowel in each state as it goes around the loop and if the vowel is present remove it.
def a(lister):
new_list=[]
for state in lister:
if 'a' in state:
state = state.replace('a',"")
if 'e' in state:
state = state.replace('e',"")
if 'i' in state:
state = state.replace('i',"")
if 'o' in state:
state = state.replace('o',"")
if 'u' in state:
state = state.replace('u',"")
new_list.append(state)
return new_list
states = [ "california" ]
print(a(states))