Skip to content

Commit 3629322

Browse files
J08KBethanyG
authored andcommitted
MAJOR CHANGES
1 parent e155a1c commit 3629322

File tree

1 file changed

+5
-7
lines changed
  • exercises/practice/parallel-letter-frequency/.meta

1 file changed

+5
-7
lines changed

exercises/practice/parallel-letter-frequency/.meta/example.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from time import sleep
55
from queue import Queue
66

7-
total_workers = 3 # Maximum number of threads chosen arbitrarily
87

8+
TOTAL_WORKERS = 3 # Maximum number of threads chosen arbitrarily
99

1010
class LetterCounter:
1111

@@ -26,8 +26,7 @@ def count_letters(queue_of_texts, letter_to_frequency, worker_id):
2626
sleep(worker_id + 1)
2727
line_input = queue_of_texts.get()
2828
if line_input is not None:
29-
letters_in_line = Counter([idx for idx in line_input.lower() if
30-
idx.isalpha()])
29+
letters_in_line = Counter(idx for idx in line_input.lower() if idx.isalpha())
3130
letter_to_frequency.add_counter(letters_in_line)
3231
queue_of_texts.task_done()
3332
if line_input is None:
@@ -40,13 +39,12 @@ def calculate(list_of_texts):
4039
queue_of_texts.put(line)
4140
letter_to_frequency = LetterCounter()
4241
threads = []
43-
for idx in range(total_workers):
44-
worker = Thread(target=count_letters, args=(queue_of_texts,
45-
letter_to_frequency, idx))
42+
for idx in range(TOTAL_WORKERS):
43+
worker = Thread(target=count_letters, args=(queue_of_texts, letter_to_frequency, idx))
4644
worker.start()
4745
threads.append(worker)
4846
queue_of_texts.join()
49-
for _ in range(total_workers):
47+
for _ in range(TOTAL_WORKERS):
5048
queue_of_texts.put(None)
5149
for thread in threads:
5250
thread.join()

0 commit comments

Comments
 (0)