Skip to content

Instantly share code, notes, and snippets.

@codecakes
Created May 9, 2023 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecakes/8f4a07639adf2cf583969aea540ea7f5 to your computer and use it in GitHub Desktop.
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
# ==================================== #
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