Skip to content

Instantly share code, notes, and snippets.

@smerrill
Created July 30, 2012 14:47
Show Gist options
  • Save smerrill/3207483 to your computer and use it in GitHub Desktop.
Save smerrill/3207483 to your computer and use it in GitHub Desktop.
Python vs Clojure
(defn words [x] (re-seq #"[a-z]+" (lower-case x)))
(def NWORDS (frequencies (words (slurp "big.txt")))) ; @TODO: Move from slurp.
def words(text): return re.findall('[a-z]+', text.lower())
def train(features):
model = collections.defaultdict(lambda: 1)
for f in features:
model[f] += 1
return model
NWORDS = train(words(file('big.txt').read()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment