Skip to content

Instantly share code, notes, and snippets.

@glickmac
Last active December 17, 2019 20:10
Show Gist options
  • Save glickmac/003e512cf97b90217e0813750e5ffa08 to your computer and use it in GitHub Desktop.
Save glickmac/003e512cf97b90217e0813750e5ffa08 to your computer and use it in GitHub Desktop.
def Flesch_Kincaid(text):
sentences = text.split('.')
avg_sentence_len = sum(len(x.split()) for x in sentences) / len(sentences)
syllables = sum(list(map(lambda x: 1 if x in ["a","i","e","o","u","y"] else 0,text)))
word_count = len(text.split(' '))
mean_syllables_per_word = syllables/float(word_count)
return (0.39 * avg_sentence_len) + (11.8 * mean_syllables_per_word) - 15.59
print('The Flesch_Kincaid grade level of Dr. Dolittle is: ' + "{0:.3g}".format(Flesch_Kincaid(text)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment