X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=support%2Flettercount.py;h=fe1ea08b655d6ff6051520e18486acf5dceb6e95;hb=fc540fb273b1e52dc85dc60e8bbcc120edaccfb7;hp=c095cefb6a67ab9a9e21d97f85b0370c3a66e0fa;hpb=df271527a6e3e4d10da9f9be3d1e9ebea9171493;p=cipher-tools.git 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)