Last active
July 16, 2018 19:40
-
-
Save wilkens/ebc3729e4a2da32998dd3959dbe87dc3 to your computer and use it in GitHub Desktop.
Count syllables
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
# 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