Created
April 28, 2013 00:03
-
-
Save mietek/5475252 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
from __future__ import division | |
def is_letter(c): | |
return c >= 'A' and c <= 'Z' or c >= 'a' and c <= 'z' | |
def score_word(s): | |
return len(filter(is_letter, s)) / len(s) | |
def average(s): | |
return sum(s) / len(s) | |
def score_phrase(s): | |
return average(map(score_word, s.split())) | |
# >>> score_phrase("Hello, world!") | |
# 0.8333333333333334 |
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
len xs = realToFrac (length xs) | |
isLetter c = c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' | |
scoreWord s = len (filter isLetter s) / len s | |
average s = sum s / len s | |
scorePhrase s = average (map scoreWord (words s)) | |
-- > scorePhrase "Hello, world!" | |
-- 0.8333333333333334 |
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
len = realToFrac . length | |
isLetter c = c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' | |
scoreWord s = len (filter isLetter s) / len s | |
average s = sum s / len s | |
scorePhrase = average . map scoreWord . words | |
-- > scorePhrase "Hello, world!" | |
-- 0.8333333333333334 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment