X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=support%2Flettercount.py;h=fe1ea08b655d6ff6051520e18486acf5dceb6e95;hb=0aba14800ccc6afc428cbcb9d89d7cdb9ea59182;hp=4a7082d1068669762d1c8526c761382d07ed6182;hpb=311b300d197536622980f7a837294d8245e326b4;p=cipher-tools.git diff --git a/support/lettercount.py b/support/lettercount.py index 4a7082d..fe1ea08 100644 --- a/support/lettercount.py +++ b/support/lettercount.py @@ -1,16 +1,13 @@ import collections import string - -def sanitise(text): - return [l.lower() for l in text if l in string.ascii_letters] +from utilities import sanitise 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)