+ 1

Intermediate python 7.2 - Ignore the vowels - Practice help

How do you solve this? Given a word as input, output a list, containing only the letters of the word that are not vowels. The vowels are a, e, i, o, u. Sample Input awesome Sample Output ['w', 's', 'm'] word = input()

1st Jul 2021, 7:07 PM
Zach Z
17 odpowiedzi
+ 7
Try this word = "hello" vowels = "aeiou" result = [] for letter in word: if letter not in vowels: result.append(letter) print(result)
1st Jul 2021, 11:43 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Here are two one-liner solutions: #1 print([x for x in input() if x.lower() not in "aeiou"]) #2 print(list(filter(lambda x: x not in "AEIOUaeiou", input()))) # Hope this helps
2nd Jul 2021, 4:00 PM
Calvin Thomas
Calvin Thomas - avatar
+ 2
Try this innovative solution 😀 --------------------------- word=input() y=set(word) z=y-{'a','e','i','o','u'} print(list(z)) --------------------------- used the concept of sets then again transformed into list. Have fun
13th Feb 2022, 4:41 AM
Sanjim Chowdhury
Sanjim Chowdhury - avatar
+ 1
There are a number of ways to do this. Can you attach your attempt so we may guide you to a solution
1st Jul 2021, 7:16 PM
Rik Wittkopp
Rik Wittkopp - avatar
0
Take empty list. By loop, extract each letter from input string, and if not vowel add to list. else don't . Finally print list. I solve this way. How do you going to code ...? What do you tried so for..? Try and post your attempt, if unsolved..
1st Jul 2021, 7:18 PM
Jayakrishna 🇮🇳
0
Stuck, not sure where to start. Can someone help? Rik Wittkopp Jayakrishna🇮🇳 Václav Dostál thanks!
1st Jul 2021, 9:14 PM
Zach Z
0
''' This is really basic stuff, which indicates you should review the sections you have completed. Example code attached''' word = "awsome" vowels = "aeiou" for letter in word: if letter not in vowels: print(letter)
1st Jul 2021, 9:48 PM
Rik Wittkopp
Rik Wittkopp - avatar
0
Appreciate the help, but not so simple as thah doesnt work…. @rRik Wittkopp For Hello, that gives an output of: h, l, l And needs to be [‘h’ , ‘l’, ‘l’] Code: word = input() vowels = ('a','e','o','i','u') #doesnt work with vowels = “aeiou” either for letter in word: if letter not in vowels: print(letter)
1st Jul 2021, 9:58 PM
Zach Z
0
Thanks - this worked: word = input() vowels = ('a','e','o','i','u') result = [] for letter in word: if letter not in vowels: result.append(letter) print(result)
2nd Jul 2021, 12:17 AM
Zach Z
0
word = input() vowels = ['a', 'e', 'i', 'o', 'u'] letters = [i for i in word if i not in str(vowels)] print(letters)
14th Aug 2021, 9:15 AM
Derrick Gacheru
0
word = input() print(list(i for i in word if i not in "aeiou"))
17th Sep 2021, 12:11 AM
Mateo González Bufi
Mateo González Bufi - avatar
0
word = input() not_vowels = [i for i in word if i not in ['a', 'e', 'i', 'o', 'u']] print(not_vowels)
10th Dec 2021, 12:39 AM
Mohammad Jamal Mahmoud Al Jadallah
Mohammad Jamal Mahmoud Al Jadallah - avatar
0
vow = ['a', 'e', 'i', 'o', 'u'] word = input() list = [i for i in word if i not in vow] print(list)
21st May 2022, 7:12 AM
Junior Jackson
Junior Jackson - avatar
0
word = input() vowels = ['a', 'e', 'i', 'o', 'u'] result = [letter for letter in word if letter not in vowels] print(result)
16th Aug 2023, 11:31 AM
Marcin Lubaczewski
0
word = input() vowels = ('a','e','i','o','u') not_vowels = [i for i in word if i not in vowels] print(not_vowels)
23rd Aug 2023, 2:29 PM
Kikvi
Kikvi - avatar
- 1
Yes, there is a lot of way, how to solve it. One way is list comprehension. Try it.
1st Jul 2021, 7:20 PM
Václav Dostál
Václav Dostál - avatar
2nd Jul 2021, 2:46 PM
Shahriyar Nur Rimon