def count_words(training_set):
 counts = defaultdict((lambda : [0, 0]))
 for (message, is_spam) in training_set:
  for word in tokenize(message):
   counts[word][(0 if is_spam else 1)] += 1
 return counts

def count_words ( training_set ) : counts = defaultdict ( ( lambda : [ 0 , 0 ] ) ) for ( message , is_spam ) in training_set : for word in tokenize ( message ) : counts [ word ] [ ( 0 if is_spam else 1 ) ] += 1 return counts
training set consists of pairs .