Wednesday, 5 December 2018

python - From a string, how do you return only the words that don't begin with a vowel?

I have a string E.g. "A dog is a good pet"



I would like to be able to return only the words that begin with a consonant. ["dog", "good", "pet"] as a list



def consonant_first(newstr):
for char in newstr.split():
if char[0] in newstr.split() == vowels1:
return newstr.split()

print(newstr)

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...