Last active
December 17, 2019 20:10
-
-
Save glickmac/003e512cf97b90217e0813750e5ffa08 to your computer and use it in GitHub Desktop.
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
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