Created
May 9, 2023 21:53
-
-
Save codecakes/8f4a07639adf2cf583969aea540ea7f5 to your computer and use it in GitHub Desktop.
Calculate the difference between sum of all consonant chars and sum of all vowel chars
This file contains hidden or 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
# ==================================== # | |
VOWELS = ['a', 'e', 'i', 'o', 'u', "A", "E", "I", "O", "U"] | |
def calc_epigram(sentence: str) -> int: | |
return sum(ord(char) if char not in VOWELS else -ord(char) for char in filter(lambda x: x.isalpha(), sentence)) | |
assert (calc_epigram("why and how")) == 569 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment