From 8bbfeef1a3d3c52a8968ebc32f3139bd14ab9a6d Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Wed, 28 Nov 2012 12:56:14 +0100 Subject: Little performance optimization. --- source/utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/utils.py b/source/utils.py index 475f3c06..b1392b0e 100755 --- a/source/utils.py +++ b/source/utils.py @@ -160,9 +160,8 @@ def top_words(articles, n=10, size=5): words = Counter() wordre = re.compile(r'\b\w{%s,}\b' % size, re.I) for article in articles: - for word in wordre.findall(clear_string(article["article_content"])): - if word.lower() not in stop_words: - words[word.lower()] += 1 + for word in [elem.lower() for elem in wordre.findall(clear_string(article["article_content"])) if elem.lower() not in stop_words]: + words[word] += 1 return words.most_common(n) def tag_cloud(tags, query="word_count"): -- cgit