+ 1
Python code coach: Remove the vowels
Currently stuck on the 7.2 intermediate python lesson to remove vowels and have them print in brackets. Code: word = input() vowels = ('a', 'e', 'i', 'o', 'u') result = [] for letter in word: if letter not in vowels: result.append(letter) print(result) Input: Hello Expected result: ['h','l','l'] Actually result: ['h'] ['h'] ['h','l'] ['h','l','l'] ['h','l','l'] So while I do ultimately get the correct answer by the fourth iteration it runs a check on each line one letter at a time. I'm lost as to how to get it to print only the final line. TIA
3 Respuestas
+ 5
Move the print statement from inside the loop to after the loop.
+ 1
Thank you, I didn't think about the nesting.
0
vow = ['a', 'e', 'i', 'o', 'u']
word = input()
list = [i for i in word if i not in vow]
print(list)