November 2015
Intermediate to advanced
304 pages
5h 23m
English
Chapter 3

1 #!/usr/bin/env python 2 3 import sys, string 4 # the global list of [word, frequency] pairs 5 word_freqs = [] 6 # the list of stop words 7 with open('../stop_words.txt') as f: 8 stop_words = f.read().split(',') 9 stop_words.extend(list(string.ascii_lowercase)) 10 11 # iterate through the file one line at a time 12 for line in open(sys.argv[1]): 13 start_char = None 14 i = 0 15 for c in line: 16 if start_char == None: 17 if c.isalnum(): 18 # We found the start of a word 19 start_char = i 20 else: 21 if not c.isalnum(): ...