aboutsummaryrefslogtreecommitdiff
path: root/utils.py
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2010-07-05 22:25:10 +0200
committercedricbonhomme <devnull@localhost>2010-07-05 22:25:10 +0200
commit36c209c16e16d75a76dcbea3e951b7746316d776 (patch)
tree01a7bfaae65284b8cbabf271ab0e2ee911abdda9 /utils.py
parentUse of collections.Counter() (new in Python 2.7) object instead of defaultDict. (diff)
downloadnewspipe-36c209c16e16d75a76dcbea3e951b7746316d776.tar.gz
newspipe-36c209c16e16d75a76dcbea3e951b7746316d776.tar.bz2
newspipe-36c209c16e16d75a76dcbea3e951b7746316d776.zip
Use of most_common() method of collections.Counter() object (new in Python 2.7)
Diffstat (limited to 'utils.py')
-rwxr-xr-xutils.py5
1 files changed, 1 insertions, 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):
"""
bgstack15