#!/usr/bin/env python

import sys, re, operator, string, inspect

#
# The functions
#
def extract_words(path_to_file):
    """
    Takes a path to a file and returns the non-stop
    words, after properly removing nonalphanumeric chars
    and normalizing for lower case
    """
    if type(path_to_file) is not str or not path_to_file:
        return []

    try:
        with open(path_to_file) as f:
            str_data = f.read()
    except IOError as e:
        print "I/O error({0}) when opening {1}: {2}".format(e.errno, path_to_file, e.strerror)
        return []
    
    pattern = re.compile('[\W_]+')
    word_list = pattern.sub(' ', str_data).lower().split()

    try:
        with open('../stop_words.txt') as f:
            stop_words = f.read().split(',')
    except IOError as e:
        print "I/O error({0}) when opening ../stops_words.txt: {1}".format(e.errno, e.strerror)
        return []

    stop_words.extend(list(string.ascii_lowercase))
    return [w for w in word_list if not w in stop_words]

def frequencies(word_list):
    """
    Takes a list of words and returns a dictionary associating
    words with frequencies of occurrence
    """
    if type(word_list) is not list or word_list == []:
        return {}

    word_freqs = {}
    for w in word_list:
        if w in word_freqs:
            word_freqs[w] += 1
        else:
            word_freqs[w] = 1
    return word_freqs

def sort(word_freq):
    """
    Takes a dictionary of words and their frequencies
    and returns a list of pairs where the entries are
    sorted by frequency 
    """
    if type(word_freq) is not dict or word_freq == {}:
        return []

    return sorted(word_freq.iteritems(), key=operator.itemgetter(1), reverse=True)

#
# The main function
#
filename = sys.argv[1] if len(sys.argv) > 1 else "../input.txt"
word_freqs = sort(frequencies(extract_words(filename)))

for tf in word_freqs[0:25]:
    print tf[0], ' - ', tf[1]


@@ -15,17 +15,16 @@
  python%0A
-%0A
 import s
@@ -115,168 +115,8 @@
 e):%0A
-    %22%22%22%0A    Takes a path to a file and returns the non-stop%0A    words, after properly removing nonalphanumeric chars%0A    and normalizing for lower case%0A    %22%22%22%0A
     
@@ -503,16 +503,127 @@
 .split()
+%0A    return word_list%0A%0Adef remove_stop_words(word_list):%0A    if type(word_list) is not list:%0A        return %5B%5D 
 %0A%0A    tr
@@ -997,128 +997,8 @@
 t):%0A
-    %22%22%22%0A    Takes a list of words and returns a dictionary associating%0A    words with frequencies of occurrence%0A    %22%22%22%0A
     
@@ -1262,157 +1262,8 @@
 q):%0A
-    %22%22%22%0A    Takes a dictionary of words and their frequencies%0A    and returns a list of pairs where the entries are%0A    sorted by frequency %0A    %22%22%22%0A
     
@@ -1534,16 +1534,34 @@
 uencies(
+remove_stop_words(
 extract_
@@ -1577,16 +1577,17 @@
 ename)))
+)
 %0A%0Afor tf

Make constructivist program be similar to the other two.