+ 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
20 Respostas
+ 13
print([a for a in word.lower() if not a in ["a","e", "i","o","u"]])
+ 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)
+ 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
+ 2
vowel = ['a', 'e',' I ','o' ,'u']
word = input()
alpha = [letter for letter in word of letter not in vowel]
print(alpha)
+ 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])
+ 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
+ 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)
0
Thanks guys, big help Hoh Shen Yien Илья Мирошник
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)
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)
0
Here an example based in ideas above https://code.sololearn.com/c9XHw9Ci1Dzd/?ref=app
0
Makes no sense to post wrong
answers
0
Remember range will ouput intergers
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)
0
word = input()
vowels = ['a', 'e', 'i', 'o', 'u']
consonants = [letters for letters in word if letters not in vowels]
print (consonants)
0
word = input()
a = [i for i in word if i not in "aeiou"]
print(a)
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)
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)
0
this workss
word = input()
vowels = 'a', 'e', 'i', 'o', 'u'
a = [i for i in word if i not in vowels]
print(a)
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!