From 36c209c16e16d75a76dcbea3e951b7746316d776 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Mon, 5 Jul 2010 22:25:10 +0200 Subject: Use of most_common() method of collections.Counter() object (new in Python 2.7) --- utils.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/utils.py b/utils.py index f17c65cd..482a59a7 100755 --- a/utils.py +++ b/utils.py @@ -88,7 +88,6 @@ def top_words(dic_articles, n=10, size=5): """ Return the n most frequent words in a list. """ - words = {} articles_content = "" for rss_feed_id in dic_articles.keys(): for article in dic_articles[rss_feed_id]: @@ -100,9 +99,7 @@ def top_words(dic_articles, n=10, size=5): words = Counter() for word in words_gen: words[word] += 1 - top_words = sorted(words.iteritems(), - key=lambda(word, count): (-count, word))[:n] - return top_words + return words.most_common(n) def tag_cloud(tags): """ -- cgit