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 (2016, retired 2019) Lists Disemvowel

Gökhan KOÇ
Gökhan KOÇ
6,630 Points

Can someone tell me why my code is not accepted? It works on the workspaces.

When I use it on the workspaces, it clearly removes the vowels and returns a new string without any vowels but it is not accepted.

Thanks in advance everyone.

disemvowel.py
vowels = ["a","e","i","o","u"]

def disemvowel(word):
  word_l = list(word)

  for x in word_l:    
    try:
      if x in vowels or x.lower() in vowels:
              word_l.remove(x)    
    except(ValueError):
      pass

  result = ""

  for x in word_l:
    try:
      result += x
    except(ValueError):
      pass

  return result

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

You are very close. The issue is cause by modifying the iterable used in the for loop. The quick fix is to iterate over a copy word_l.

:point_right: use for x in word_l.copy(): instead!

Post back if you need more help. Good luck!!

Gökhan KOÇ
Gökhan KOÇ
6,630 Points

I've never used the "copy" method before. Now it makes sense!

Thank you!