diff options
author | cedricbonhomme <devnull@localhost> | 2010-07-05 22:25:10 +0200 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2010-07-05 22:25:10 +0200 |
commit | 36c209c16e16d75a76dcbea3e951b7746316d776 (patch) | |
tree | 01a7bfaae65284b8cbabf271ab0e2ee911abdda9 /utils.py | |
parent | Use of collections.Counter() (new in Python 2.7) object instead of defaultDict. (diff) | |
download | newspipe-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-x | utils.py | 5 |
1 files changed, 1 insertions, 4 deletions
@@ -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): """ |