From: Neil Smith Date: Fri, 16 Mar 2018 20:29:13 +0000 (+0000) Subject: Updated lettercount to use a Counter X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=863ffd84c2ae27ba4c12f9ae502682070d8dfecb;p=cipher-tools.git Updated lettercount to use a Counter --- 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)