Welcome to the Treehouse Community
Looking to learn something new?
Andy BoscoCourses Plus Student 681 Points
state_list.remove(vowel). "state_list" is a List and "vowel" is A string.
At state_list.remove(vowel). "state_list" is a List and "vowel" is A string. Python allows the remove of the String inside the List. When I tried to test my code below it won't work and got the error ValueError: list.remove(x): x not in list. Why my code doesn't work? My variable "word" is a List and "vowels" is a String.
word = ['Treehouse'] vowels = ('aeiou') word.remove(vowels) print word
Remember, to convert a 'string' to a list you can use vowel_list = list('aeiou')
This will create vowel_list as a list with the 5 elements of ['a', 'e', 'i', 'o', 'u']
You can then iterate over the vowel list
list.remove = remove(...) L.remove(value) -> None -- remove first occurrence of value. Raises ValueError if the value is not present.
list.remove will remove an item from a list, but it won't filter out parts of a string nested inside the list. By saying
["Treehouse"].remove("aeiou"), you're telling Python to remove the string
"aeiou" from the list, not from the string
"Treehouse" inside the list.
>>> word = ['Treehouse', 'aeiou'] >>> vowel = 'aeiou' >>> word ['Treehouse', 'aeiou'] >>> vowel 'aeiou' >>> word.remove(vowel) >>> word ['Treehouse'] >>> word.remove(vowel) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: list.remove(x): x not in list