Skip to content

Instantly share code, notes, and snippets.

@wilkens
Last active July 16, 2018 19:40
Show Gist options
  • Save wilkens/ebc3729e4a2da32998dd3959dbe87dc3 to your computer and use it in GitHub Desktop.
Save wilkens/ebc3729e4a2da32998dd3959dbe87dc3 to your computer and use it in GitHub Desktop.
Count syllables
# Function to calculate the syllables in a word
'''Calculate number of syllables in word. Returns a list of possible values.
Generally, will want the first item in that list.'''
from nltk.corpus import cmudict
d = cmudict.dict()
def nsyl(word):
return [len(list(y for y in x if y[-1].isdigit())) for x in d[word.lower()]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment