From c9acecf59f93004d33c19b209535072dcf932977 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Tue, 12 Nov 2013 11:34:09 +0000 Subject: [PATCH] Changed frequencies procedure to use a Counter object --- cipher.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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): -- 2.34.1