From b3bcad5bd36b5bb646d86cfcb6a6d920beaca758 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Mon, 5 Jul 2010 22:15:34 +0200 Subject: Use of collections.Counter() (new in Python 2.7) object instead of defaultDict. --- utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index f62a0e9a..f17c65cd 100755 --- a/utils.py +++ b/utils.py @@ -28,7 +28,7 @@ from BeautifulSoup import BeautifulSoup from datetime import datetime from string import punctuation -from collections import defaultdict +from collections import Counter from collections import OrderedDict from StringIO import StringIO @@ -97,7 +97,7 @@ def top_words(dic_articles, n=10, size=5): words_gen = [word for word in articles_content.split() if len(word) > size] words_gen = [word.strip(punctuation).lower() for word in words_gen] - words = defaultdict(int) + words = Counter() for word in words_gen: words[word] += 1 top_words = sorted(words.iteritems(), -- cgit