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

Sohail Mirza
seal-mask
.a{fill-rule:evenodd;}techdegree
Sohail Mirza
Python Web Development Techdegree Student 5,158 Points

Why doesnt my code work

Please advise where am i going wrong this question

disemvowel.py
def disemvowel(word):
    exception = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
    test = list(word)
    test.remove(exception)
    return word

2 Answers

Steven Parker
Steven Parker
231,275 Points

The "remove" method only removes something that matches the argument, so if you pass it a list it will only remove an element that is an exact duplicate of that entire list.

And a few other hints:

  • to remove individual letters, you will probably want to use a loop
  • if you modify "test" but then "return word", the output of the function will be unchanged
  • there are possible solutions that do not require converting the string to a list
  • if you do convert the word to a list, remember to convert it back to a string before returning it
Sohail Mirza
seal-mask
.a{fill-rule:evenodd;}techdegree
Sohail Mirza
Python Web Development Techdegree Student 5,158 Points

Hi Steven

Thanks for your reply. I am slighty confused as i ran by own example and it did not work. fruits = ["apple", "pear", "banana"] choice = ["apple"] fruits.remove(choice)

in this example i get an error.

Why is this the case

Steven Parker
Steven Parker
231,275 Points

Let's say you have this list "test = ['a', 'b', 'c', 'd']" and another list "bits = ['a', 'b', 'c']".

So if you do "test.remove(bits)" nothing will happen.

But if you started with this list inside of a list instead: "test = [['a', 'b', 'c'], 'd']" and then did "test.remove(bits)", that would leave you with just "['d']" in "test" because part of test was another list that was exactly like "bits".

Does that clear it up?

Kevin Apetrei
Kevin Apetrei
2,447 Points

Tip:

You can always use (.upper) or (.lower) to simplify the (exception).

E.g: exception.lower = ("a", "e", "i", "o", "u") or exception.upper = ("A", "E", "I", "O", "U") that makes it so if you use uppercase or lowercase it will still work.