From: Neil Smith Date: Tue, 12 Nov 2013 11:34:09 +0000 (+0000) Subject: Changed frequencies procedure to use a Counter object X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=c9acecf59f93004d33c19b209535072dcf932977;p=cipher-tools.git Changed frequencies procedure to use a Counter object --- diff --git a/cipher.py b/cipher.py index bc173a7..d738d88 100644 --- a/cipher.py +++ b/cipher.py @@ -120,11 +120,14 @@ def frequencies(text): ('h', 2), ('i', 1), ('j', 1), ('k', 1), ('l', 1), ('m', 1), ('n', 1), ('o', 4), ('p', 1), ('q', 1), ('r', 2), ('t', 2), ('u', 2), ('v', 1), ('w', 1), ('x', 1), ('y', 1), ('z', 1)] + >>> frequencies('abcdefabcdef')['x'] + 0 """ - counts = collections.defaultdict(int) - for c in text: - counts[c] += 1 - return counts + #counts = collections.defaultdict(int) + #for c in text: + # counts[c] += 1 + #return counts + return collections.Counter(c for c in text) letter_frequencies = frequencies def deduplicate(text):