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 trialavinash singh
549 Pointsremove list item
i am not able to remove word from list
def disemvowel(word):
L = ["a", "e", "i", "o","u"]
for N in L:
av = list(word.lower())
for M in av:
if M == N:
av.remove(M)
world = str(av)
return word
1 Answer
Steven Parker
231,269 PointsNever remove items inside a loop from the iterable that is controlling the loop. This can case side-effects such as items being skipped over. Instead, you could iterate using a copy of the iterable (easily made with a slice), or you could create a new result in the loop and return that.
Also, don't convert the entire word to lower case. This will potentially modify some of the letters that you intend to keep (they should remain unchanged).
I don't think you can use "str" to convert a list into a string, but you can do it with "join".
And check your variable names. The code creates "world" but returns "word" (which is the original argument unchanged).
avinash singh
549 Pointsavinash singh
549 PointsThank u