#!/usr/bin/env python
import sys, operator, string

def characters(filename):
    for line in open(filename):
        for c in line:
            yield c

def all_words(filename):
    start_char = True
    for c in characters(filename):
        if start_char == True:
            word = ""
            if c.isalnum():
                # We found the start of a word
                word = c.lower()
                start_char = False
            else: pass
        else:
            if c.isalnum():
                word += c.lower()
            else:
                # We found end of word, emit it
                start_char = True
                yield word

def non_stop_words(filename):
    stopwords = set(open('../stop_words.txt').read().split(',')  + list(string.ascii_lowercase))
    for w in all_words(filename):
        if not w in stopwords:
            yield w

def count_and_sort(filename):
    freqs = {}
    for w in non_stop_words(filename):
        freqs[w] = 1 if w not in freqs else freqs[w]+1
    return sorted(freqs.iteritems(), key=operator.itemgetter(1), reverse=True)

#
# The main function
#
word_freqs = count_and_sort(sys.argv[1])
for (w, c) in word_freqs[0:25]:
    print w, ' - ', c


@@ -908,13 +908,19 @@
 reqs
+, i
  = %7B%7D
+, 1
 %0A   
@@ -1018,14 +1018,141 @@
     
-return
+    if i %25 5000 == 0:%0A            yield sorted(freqs.iteritems(), key=operator.itemgetter(1), reverse=True)%0A        i = i+1%0A    yield
  sor
@@ -1216,17 +1216,16 @@
 e=True)%0A
-%0A
 #%0A# The 
@@ -1240,16 +1240,20 @@
 ction%0A#%0A
+for 
 word_fre
@@ -1255,17 +1255,18 @@
 d_freqs 
-=
+in
  count_a
@@ -1285,17 +1285,64 @@
 argv%5B1%5D)
-%0A
+:%0A    print %22-----------------------------%22%0A    
 for (w, 
@@ -1365,16 +1365,20 @@
 %5B0:25%5D:%0A
+    
     prin

Make the last function also a generator, so that the explanation flows better