Skip to content

Instantly share code, notes, and snippets.

@damianmoore
Last active December 27, 2015 17:19
Show Gist options
  • Save damianmoore/7361670 to your computer and use it in GitHub Desktop.
Save damianmoore/7361670 to your computer and use it in GitHub Desktop.
Syllables
VOWELS = ['a', 'e', 'i', 'o', 'u',]
def syllables(word):
''' Really basic syllable counter '''
num = 0
previously_vowel = False
for char in word:
if char in VOWELS:
if not previously_vowel:
num += 1
previously_vowel = True
else:
previously_vowel = False
return num
from hyphen import Hyphenator
def syllables2(word):
''' Better syllable counter using PyHyphen '''
h_gb = Hyphenator('en_GB')
return len(h_gb.syllables(u'ligature'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment