Finally rewrote the code for Python3!

This commit is contained in:
Crista Lopes
2018-12-13 19:57:17 -08:00
parent 4449f0b7ba
commit ed8c3cabaa
47 changed files with 70 additions and 115 deletions

View File

@@ -1,10 +1,9 @@
#!/usr/bin/env python
from __future__ import print_function
import re, sys, operator, Queue, threading
import re, sys, operator, queue, threading
# Two data spaces
word_space = Queue.Queue()
freq_space = Queue.Queue()
word_space = queue.Queue()
freq_space = queue.Queue()
stopwords = set(open('../stop_words.txt').read().split(','))
@@ -15,7 +14,7 @@ def process_words():
while True:
try:
word = word_space.get(timeout=1)
except Queue.Empty:
except queue.Empty:
break
if not word in stopwords:
if word in word_freqs:
@@ -42,12 +41,12 @@ for i in range(5):
word_freqs = {}
while not freq_space.empty():
freqs = freq_space.get()
for (k, v) in freqs.iteritems():
for (k, v) in freqs.items():
if k in word_freqs:
count = sum(item[k] for item in [freqs, word_freqs])
else:
count = freqs[k]
word_freqs[k] = count
for (w, c) in sorted(word_freqs.iteritems(), key=operator.itemgetter(1), reverse=True)[:25]:
for (w, c) in sorted(word_freqs.items(), key=operator.itemgetter(1), reverse=True)[:25]:
print(w, '-', c)