+ 1
Can you help me?
What can I do to print only the consonants of word (in this case the output would be "Prn")? https://code.sololearn.com/cre7uN1dO7DO/?ref=app
3 Antworten
+ 5
hi Lorenzo, i took your code and did only very minor changes. I added a list to collect the found consonants, and changed the indentation of return. You can find it here:
https://code.sololearn.com/cBe2J20OCzwT/?ref=app
+ 2
1) turn your function into a generator:
Replace "return" with "yield" and use a statement like print(*consonants(stringy), sep='') to get the output
2) use a list comprehension:
print(''.join([c for c in stringy if c.lower() not in vowels]))
0
Elegant solution in so small code! I like it.