From 0520c182beb16cf9fcd12744444d30220fbe3768 Mon Sep 17 00:00:00 2001 From: Crista Lopes Date: Tue, 24 Dec 2019 06:47:54 -0800 Subject: [PATCH] Finish the last commit --- 29-actors/tf-29.py | 3 ++- 31-map-reduce/tf-31.py | 11 ++--------- 32-double-map-reduce/tf-32.py | 11 ++--------- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/29-actors/tf-29.py b/29-actors/tf-29.py index 34df07a..684fb3b 100755 --- a/29-actors/tf-29.py +++ b/29-actors/tf-29.py @@ -1,4 +1,5 @@ #!/usr/bin/env python + import sys, re, operator, string from threading import Thread from queue import Queue @@ -113,7 +114,7 @@ class WordFrequencyController(ActiveWFObject): def _display(self, message): word_freqs = message[0] for (w, f) in word_freqs[0:25]: - print(w, ' - ', f) + print(w, '-', f) send(self._storage_manager, ['die']) self._stopMe = True diff --git a/31-map-reduce/tf-31.py b/31-map-reduce/tf-31.py index cd7b866..298a3eb 100755 --- a/31-map-reduce/tf-31.py +++ b/31-map-reduce/tf-31.py @@ -1,13 +1,6 @@ #!/usr/bin/env python import sys, re, operator, string from functools import reduce - -try: - xrange # Python 2 -except NameError: - xrange = range # Python 3 - - # # Functions for map reduce # @@ -17,7 +10,7 @@ def partition(data_str, nlines): into chunks of nlines. """ lines = data_str.split('\n') - for i in xrange(0, len(lines), nlines): + for i in range(0, len(lines), nlines): yield '\n'.join(lines[i:i+nlines]) def split_words(data_str): @@ -77,4 +70,4 @@ splits = map(split_words, partition(read_file(sys.argv[1]), 200)) word_freqs = sort(reduce(count_words, splits)) for (w, c) in word_freqs[0:25]: - print(w, ' - ', c) + print(w, '-', c) diff --git a/32-double-map-reduce/tf-32.py b/32-double-map-reduce/tf-32.py index 33620d4..02562ae 100755 --- a/32-double-map-reduce/tf-32.py +++ b/32-double-map-reduce/tf-32.py @@ -1,13 +1,6 @@ #!/usr/bin/env python import sys, re, operator, string from functools import reduce - -try: - xrange # Python 2 -except NameError: - xrange = range # Python 3 - - # # Functions for map reduce # @@ -17,7 +10,7 @@ def partition(data_str, nlines): into chunks of nlines. """ lines = data_str.split('\n') - for i in xrange(0, len(lines), nlines): + for i in range(0, len(lines), nlines): yield '\n'.join(lines[i:i+nlines]) def split_words(data_str): @@ -94,4 +87,4 @@ splits_per_word = regroup(splits) word_freqs = sort(map(count_words, splits_per_word.items())) for (w, c) in word_freqs[0:25]: - print(w, ' - ', c) + print(w, '-', c)