Skip to content

Instantly share code, notes, and snippets.

@ThomasRettig
Last active January 15, 2022 09:23
Show Gist options
  • Save ThomasRettig/33a926fe0ab290209170661d87d31cda to your computer and use it in GitHub Desktop.
Save ThomasRettig/33a926fe0ab290209170661d87d31cda to your computer and use it in GitHub Desktop.
Extract consonants from a given string
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"
@ThomasRettig
Copy link
Author

ThomasRettig commented Jan 15, 2022

TODO: Make sure that diacritical consonants (such as č and ñ) are passed as consonants instead of vowels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment