def ngram(n, words):
    for i in xrange(len(words)-n+1):
        yield words[i:i+n]

def getWords(filename):
    words = []
    with open(filename) as f:
        for line in f.readlines():
            words += line.split()
	return words

def frequencyTop(top_n, words):
    from collections import Counter
    return Counter(map(tuple, words)).most_common(top_n)

if __name__ == "__main__":

    print frequencyTop(5, ngram(1, getWords("big-seg.txt")))
    print frequencyTop(5, ngram(2, getWords("big-seg.txt")))
    print frequencyTop(5, ngram(5, getWords("big-seg.txt")))
@@ -111,18 +111,35 @@
     
-words = %5B%5D
+from itertools import chain
 %0A   
@@ -173,86 +173,70 @@
     
-    for line in f.readlines():%0A            words += line.split()%0A%09return words
+%09return list(chain(*(line.split() for line in f.readlines())))
 %0A%0Ade

decrease loc of getwords