From 863ffd84c2ae27ba4c12f9ae502682070d8dfecb Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Fri, 16 Mar 2018 20:29:13 +0000 Subject: [PATCH] Updated lettercount to use a Counter --- support/lettercount.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/support/lettercount.py b/support/lettercount.py index c095cef..fe1ea08 100644 --- a/support/lettercount.py +++ b/support/lettercount.py @@ -2,16 +2,12 @@ import collections import string from utilities import sanitise -# def sanitise(text): -# return [l.lower() for l in text if l in string.ascii_letters] - corpora = ['shakespeare.txt', 'sherlock-holmes.txt', 'war-and-peace.txt'] -counts = collections.defaultdict(int) +counts = collections.Counter() for corpus in corpora: text = sanitise(open(corpus, 'r').read()) - for letter in text: - counts[letter] += 1 + counts.update(text) sorted_letters = sorted(counts, key=counts.get, reverse=True) -- 2.34.1