diff --git a/01-good-old-times/tf-01.py b/01-good-old-times/tf-01.py index bd8caea..ac24994 100755 --- a/01-good-old-times/tf-01.py +++ b/01-good-old-times/tf-01.py @@ -120,6 +120,6 @@ while True: for tf in data[0:25]: # elimination of symbol tf is exercise if len(tf) == 2: - print(tf[0], ' - ', tf[1]) + print(tf[0], '-', tf[1]) # We're done word_freqs.close() diff --git a/02-go-forth/tf-02.py b/02-go-forth/tf-02.py index 9b6f5bc..5e2d7c9 100755 --- a/02-go-forth/tf-02.py +++ b/02-go-forth/tf-02.py @@ -104,7 +104,7 @@ stack.append(0) # the last word there will be one item left while stack[-1] < 25 and len(stack) > 1: heap['i'] = stack.pop() - (w, f) = stack.pop(); print(w, ' - ', f) + (w, f) = stack.pop(); print(w, '-', f) stack.append(heap['i']); stack.append(1) stack.append(stack.pop() + stack.pop()) diff --git a/03-arrays/tf-03.py b/03-arrays/tf-03.py index bf79ef6..93a3702 100644 --- a/03-arrays/tf-03.py +++ b/03-arrays/tf-03.py @@ -1,10 +1,10 @@ import sys, string import numpy as np -# Example input: "Hello World!!" +# Example input: "Hello World!" characters = np.array([' ']+list(open(sys.argv[1]).read())+[' ']) # Result: array([' ', 'H', 'e', 'l', 'l', 'o', ' ', ' ', -# 'W', 'o', 'r', 'l', 'd', '!', '!', ' '], dtype=' 1)] +w_ranges = w_ranges[np.where(w_ranges[:, 1] - w_ranges[:, 0] > 2)] # Result: array([[ 0, 6], # [ 7, 13]], dtype=int64) @@ -38,9 +38,7 @@ swords = np.array(list(map(lambda w: ''.join(w).strip(), words))) # Result: array(['hello', 'world'], dtype=' 0): - print(word_freqs[0][0], ' - ', word_freqs[0][1]) + print(word_freqs[0][0], '-', word_freqs[0][1]) print_all(word_freqs[1:]); # diff --git a/07-code-golf/tf-07.py b/07-code-golf/tf-07.py index 8aedd14..999e30f 100755 --- a/07-code-golf/tf-07.py +++ b/07-code-golf/tf-07.py @@ -3,4 +3,4 @@ import heapq, re, sys words = re.findall("[a-z]{2,}", open(sys.argv[1]).read().lower()) for w in heapq.nlargest(25, set(words) - set(open("../stop_words.txt").read().split(",")), words.count): - print(w, "-", words.count(w)) + print(w, '-', words.count(w)) diff --git a/08-infinite-mirror/tf-08.py b/08-infinite-mirror/tf-08.py index 68b750e..03964db 100755 --- a/08-infinite-mirror/tf-08.py +++ b/08-infinite-mirror/tf-08.py @@ -34,7 +34,6 @@ def wf_print(wordfreq): stop_words = set(open('../stop_words.txt').read().split(',')) words = re.findall('[a-z]{2,}', open(sys.argv[1]).read().lower()) - word_freqs = {} # Theoretically, we would just call count(words, stop_words, word_freqs) # Try doing that and see what happens. diff --git a/09-kick-forward/tf-09.py b/09-kick-forward/tf-09.py index ecf1b53..b07fe70 100755 --- a/09-kick-forward/tf-09.py +++ b/09-kick-forward/tf-09.py @@ -40,7 +40,7 @@ def sort(wf, func): def print_text(word_freqs, func): for (w, c) in word_freqs[0:25]: - print(w, "-", c) + print(w, '-', c) func(None) def no_op(func): diff --git a/11-things/tf-11.py b/11-things/tf-11.py index 631b505..cd9f75a 100755 --- a/11-things/tf-11.py +++ b/11-things/tf-11.py @@ -73,7 +73,7 @@ class WordFrequencyController(TFExercise): word_freqs = self._word_freq_manager.sorted() for (w, c) in word_freqs[0:25]: - print(w, ' - ', c) + print(w, '-', c) # # The main function diff --git a/12-letterbox/tf-12.py b/12-letterbox/tf-12.py index 56eb7d0..1323556 100755 --- a/12-letterbox/tf-12.py +++ b/12-letterbox/tf-12.py @@ -89,7 +89,7 @@ class WordFrequencyController(): word_freqs = self._word_freq_manager.dispatch(['sorted']) for (w, c) in word_freqs[0:25]: - print(w, ' - ', c) + print(w, '-', c) # # The main function diff --git a/13-closed-maps/tf-13.py b/13-closed-maps/tf-13.py index 56c9527..463dad9 100644 --- a/13-closed-maps/tf-13.py +++ b/13-closed-maps/tf-13.py @@ -46,4 +46,4 @@ for w in data_storage_obj['words'](): word_freqs = word_freqs_obj['sorted']() for (w, c) in word_freqs[0:25]: - print(w, ' - ', c) + print(w, '-', c) diff --git a/14-abstract-things/tf-14.py b/14-abstract-things/tf-14.py index 6ca42f6..8aba3b1 100755 --- a/14-abstract-things/tf-14.py +++ b/14-abstract-things/tf-14.py @@ -94,7 +94,7 @@ class WordFrequencyController: word_freqs = self._word_freq_counter.sorted() for (w, c) in word_freqs[0:25]: - print(w, ' - ', c) + print(w, '-', c) # # The main function diff --git a/15-hollywood/tf-15.py b/15-hollywood/tf-15.py index 3a579ae..31dec3b 100755 --- a/15-hollywood/tf-15.py +++ b/15-hollywood/tf-15.py @@ -89,7 +89,7 @@ class WordFrequencyCounter: def __print_freqs(self): word_freqs = sorted(self._word_freqs.items(), key=operator.itemgetter(1), reverse=True) for (w, c) in word_freqs[0:25]: - print(w, ' - ', c) + print(w, '-', c) # # The main function diff --git a/16-bulletin-board/tf-16.py b/16-bulletin-board/tf-16.py index 52061b9..4ada547 100755 --- a/16-bulletin-board/tf-16.py +++ b/16-bulletin-board/tf-16.py @@ -79,7 +79,7 @@ class WordFrequencyCounter: def print_freqs(self, event): word_freqs = sorted(self._word_freqs.items(), key=operator.itemgetter(1), reverse=True) for (w, c) in word_freqs[0:25]: - print(w, ' - ', c) + print(w, '-', c) class WordFrequencyApplication: def __init__(self, event_manager): diff --git a/17-introspective/tf-17.py b/17-introspective/tf-17.py index 7d54faf..0033b4f 100755 --- a/17-introspective/tf-17.py +++ b/17-introspective/tf-17.py @@ -39,7 +39,7 @@ def sort(word_freq): def main(): word_freqs = sort(frequencies(extract_words(sys.argv[1]))) for (w, c) in word_freqs[0:25]: - print(w, ' - ', c) + print(w, '-', c) if __name__ == "__main__": main() diff --git a/18-reflective/tf-18.py b/18-reflective/tf-18.py index 1abd4c0..4629298 100755 --- a/18-reflective/tf-18.py +++ b/18-reflective/tf-18.py @@ -44,5 +44,5 @@ exec('sort = ' + sort_func) word_freqs = locals()['sort'](locals()['frequencies'](locals()['extract_words'](filename))) for (w, c) in word_freqs[0:25]: - print(w, ' - ', c) + print(w, '-', c) diff --git a/19-aspects/tf-19.py b/19-aspects/tf-19.py index b3a22b9..4baf7b1 100755 --- a/19-aspects/tf-19.py +++ b/19-aspects/tf-19.py @@ -45,5 +45,5 @@ for func in tracked_functions: word_freqs = sort(frequencies(extract_words(sys.argv[1]))) for (w, c) in word_freqs[0:25]: - print(w, ' - ', c) + print(w, '-', c) diff --git a/20-plugins/tf-20.py b/20-plugins/tf-20.py index b7cf0cf..6300fe9 100755 --- a/20-plugins/tf-20.py +++ b/20-plugins/tf-20.py @@ -7,8 +7,6 @@ def load_plugins(): words_plugin = config.get("Plugins", "words") frequencies_plugin = config.get("Plugins", "frequencies") global tfwords, tffreqs -# tfwords = importlib.load_compiled('tfwords', words_plugin) -# tffreqs = importlib.load_compiled('tffreqs', frequencies_plugin) tfwords = importlib.machinery.SourcelessFileLoader('tfwords', words_plugin).load_module() tffreqs = importlib.machinery.SourcelessFileLoader('tffreqs', frequencies_plugin).load_module() @@ -16,5 +14,5 @@ load_plugins() word_freqs = tffreqs.top25(tfwords.extract_words(sys.argv[1])) for (w, c) in word_freqs: - print(w, ' - ', c) + print(w, '-', c) diff --git a/21-constructivist/tf-21.py b/21-constructivist/tf-21.py index 0f74c05..70c070f 100755 --- a/21-constructivist/tf-21.py +++ b/21-constructivist/tf-21.py @@ -58,5 +58,5 @@ filename = sys.argv[1] if len(sys.argv) > 1 else "../input.txt" word_freqs = sort(frequencies(remove_stop_words(extract_words(filename)))) for tf in word_freqs[0:25]: - print(tf[0], ' - ', tf[1]) + print(tf[0], '-', tf[1]) diff --git a/22-tantrum/tf-22.py b/22-tantrum/tf-22.py index 9b925b3..33c2b6e 100755 --- a/22-tantrum/tf-22.py +++ b/22-tantrum/tf-22.py @@ -1,4 +1,5 @@ #!/usr/bin/env python + import sys, re, operator, string, traceback # @@ -64,7 +65,7 @@ try: assert(type(word_freqs) is list), "OMG! This is not a list!" assert(len(word_freqs) > 25), "SRSLY? Less than 25 words!" for (w, c) in word_freqs[0:25]: - print(w, ' - ', c) + print(w, '-', c) except Exception as e: print("Something wrong: {0}".format(e)) traceback.print_exc() diff --git a/23-passive-aggressive/tf-23.py b/23-passive-aggressive/tf-23.py index fa28130..822f9bf 100644 --- a/23-passive-aggressive/tf-23.py +++ b/23-passive-aggressive/tf-23.py @@ -50,7 +50,7 @@ try: assert(len(word_freqs) > 25), "OMG! Less than 25 words! I QUIT!" for tf in word_freqs[0:25]: - print(tf[0], ' - ', tf[1]) + print(tf[0], '-', tf[1]) except Exception as e: print("Something wrong: {0}".format(e)) diff --git a/24-declared-intentions/tf-24.py b/24-declared-intentions/tf-24.py index 347776d..04a931f 100644 --- a/24-declared-intentions/tf-24.py +++ b/24-declared-intentions/tf-24.py @@ -45,5 +45,5 @@ def sort(word_freq): word_freqs = sort(frequencies(extract_words(sys.argv[1]))) for (w, c) in word_freqs[0:25]: - print(w, ' - ', c) + print(w, '-', c) diff --git a/26-persistent-tables/tf-26.py b/26-persistent-tables/tf-26.py index 8ed7224..e7bd61e 100755 --- a/26-persistent-tables/tf-26.py +++ b/26-persistent-tables/tf-26.py @@ -66,4 +66,4 @@ with sqlite3.connect('tf.db') as connection: for i in range(25): row = c.fetchone() if row != None: - print(row[0] + ' - ' + str(row[1])) + print(row[0], '-', str(row[1])) diff --git a/27-spreadsheet/tf-27.py b/27-spreadsheet/tf-27.py index 5f4ebe2..e236b1e 100755 --- a/27-spreadsheet/tf-27.py +++ b/27-spreadsheet/tf-27.py @@ -38,6 +38,7 @@ def update(): if c[1] != None: c[0] = c[1]() + # Load the fixed data into the first 2 columns all_words[0] = re.findall('[a-z]{2,}', open(sys.argv[1]).read().lower()) stop_words[0] = set(open('../stop_words.txt').read().split(',')) diff --git a/28-lazy-rivers/tf-28.py b/28-lazy-rivers/tf-28.py index fe0e675..21460c3 100755 --- a/28-lazy-rivers/tf-28.py +++ b/28-lazy-rivers/tf-28.py @@ -44,5 +44,5 @@ def count_and_sort(filename): for word_freqs in count_and_sort(sys.argv[1]): print("-----------------------------") for (w, c) in word_freqs[0:25]: - print(w, ' - ', c) + print(w, '-', c)