+ 2

List comprehension python

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'] My code attempt - alpha = ['b', 'c' ,'d', 'f', 'g' ,'h', 'j', 'k', 'l' ,'m' ,'n', 'p', 'q' ,'r', 's' ,'t', 'v', 'w' 'x', 'y', 'z'] word = input() data = [word for word in alpha if word.startswith(word)] print(data) I'm not able to split this at first or I don't know what is wrong

15th Apr 2021, 10:21 AM
Veena Tirmal
Veena Tirmal - avatar
20 Answers
+ 13
print([a for a in word.lower() if not a in ["a","e", "i","o","u"]])
15th Apr 2021, 10:59 AM
Илья Мирошник
Илья Мирошник - avatar
+ 7
I got one! word=input() word=list(word) vowels=['a','e','i','o','u'] left=[l for l in word if not l in vowels] print(left)
7th Aug 2021, 6:46 AM
Lukia Shaw
+ 3
It's [letter for letter in word if letter in alpha] List conprehension has two parts, the loop and condition, so you must loop all letters in word first -> letter for letter in word and follow with condition Another way to improve it is by declaring a list of vowels, 5 is less than 21 :D [letter for letter in word if letter not in alpha] and since you can use in for string as well, you can just simply declare vowel = "aeiou" instead of declaring a list, slightly shorter and easier to code
15th Apr 2021, 10:27 AM
Hoh Shen Yien
Hoh Shen Yien - avatar
+ 2
vowel = ['a', 'e',' I ','o' ,'u'] word = input() alpha = [letter for letter in word of letter not in vowel] print(alpha)
15th Apr 2021, 12:23 PM
Veena Tirmal
Veena Tirmal - avatar
+ 2
word = input() vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U',] print([i for i in word if i not in vowels])
14th Feb 2023, 4:01 PM
RmFrZU1FCg==
RmFrZU1FCg== - avatar
+ 1
word = input() vowels=["A","a","E","e","I","i","O","o","U","u"] key=[] for x in word: if x not in vowels: key.append(x) print(key) This will work
22nd Sep 2021, 2:05 PM
narendra kadali
narendra kadali - avatar
+ 1
My Solution: word=input() word=list(word) vowels=['a','e','i','o','u'] left=[l for l in word if not l in vowels] print(left)
10th Nov 2022, 8:21 AM
Pooja Patel
Pooja Patel - avatar
15th Apr 2021, 12:17 PM
Veena Tirmal
Veena Tirmal - avatar
0
vowels = ['a', 'e', 'i', 'o', 'u'] word = input() word = list(word) result = [letter for letter in word if not letter in vowels] print(result)
4th Oct 2021, 6:25 PM
Павел Ильминский
Павел Ильминский - avatar
0
here's my solution (similar to a few here) but in only 4 lines : word = input() vowels = ['a', 'e', 'i', 'o', 'u'] cons = [w for w in word if w not in vowels] print(cons)
5th Oct 2021, 12:59 PM
Curious George
Curious George - avatar
0
Here an example based in ideas above https://code.sololearn.com/c9XHw9Ci1Dzd/?ref=app
25th Oct 2021, 4:34 AM
Cristian Baeza Jimenez
Cristian Baeza Jimenez - avatar
0
Makes no sense to post wrong answers
8th Feb 2022, 7:17 PM
Phillip Scott
Phillip Scott - avatar
0
Remember range will ouput intergers
8th Feb 2022, 7:19 PM
Phillip Scott
Phillip Scott - avatar
0
Lukia Shaw This is the answer word=input() word=list(word) vowels=['a','e','i','o','u'] left=[l for l in word if not l in vowels] print(left) But i wonder why this doesnt work: word=input() word=list(word) left=[l for l in word if I != [‘a’,’e’,’i’,’o’,’u’] print(left)
8th Feb 2022, 7:28 PM
Phillip Scott
Phillip Scott - avatar
0
word = input() vowels = ['a', 'e', 'i', 'o', 'u'] consonants = [letters for letters in word if letters not in vowels] print (consonants)
5th Jul 2022, 2:18 PM
Oluwaseyi Abiodun Fadahunsi
Oluwaseyi Abiodun Fadahunsi - avatar
0
word = input() a = [i for i in word if i not in "aeiou"] print(a)
30th Oct 2022, 5:31 PM
Rafael Mina Piergiorge
Rafael Mina Piergiorge - avatar
0
Longer with loops word = input() z = [] for i in word: if i =="a" or i =="e" or i=="i" or i == "o" or i == "u": continue else: z.append(i) print(z)
8th Nov 2022, 9:22 PM
Hebert Aranda
0
With continue word = input() z = [] vowels = ["a","e","i","o","u"] for i in word: if i in vowels: continue else: z.append(i) print(z)
8th Nov 2022, 9:23 PM
Hebert Aranda
0
this workss word = input() vowels = 'a', 'e', 'i', 'o', 'u' a = [i for i in word if i not in vowels] print(a)
23rd Sep 2023, 11:08 AM
Richy Heizer
Richy Heizer - avatar
0
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. my answer is: w= input() a=set(w) con = {'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'} print(con & a) the set() function converts a list to a set. Hope this helps!
1st Jun 2024, 1:08 PM
Sid
Sid - avatar