+ 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

15th Apr 2019, 7:19 PM
Lorenzo
Lorenzo - avatar
3 ответов
+ 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
15th Apr 2019, 7:33 PM
Lothar
Lothar - avatar
+ 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]))
15th Apr 2019, 7:26 PM
Anna
Anna - avatar
0
Elegant solution in so small code! I like it.
17th Apr 2019, 11:08 AM
Fab Pitt (Extro)
Fab Pitt (Extro) - avatar