Last active
January 15, 2022 09:23
-
-
Save ThomasRettig/33a926fe0ab290209170661d87d31cda to your computer and use it in GitHub Desktop.
Extract consonants from a given string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def consonantExtractor(word): | |
consonants = "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ" | |
res = [] | |
for chr in str(word): | |
if chr in consonants: | |
res.extend(chr) | |
consonants = "".join(res) | |
return(consonants) | |
print(consonantExtractor("Hello world!")) | |
# Output: "Hllwrld" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: Make sure that diacritical consonants (such as
č
andñ
) are passed as consonants instead of vowels.