diff options
author | Cédric Bonhomme <kimble.mandel@gmail.com> | 2013-02-03 00:30:23 +0100 |
---|---|---|
committer | Cédric Bonhomme <kimble.mandel@gmail.com> | 2013-02-03 00:30:23 +0100 |
commit | 33ef607cecb94f325ceb31d4f4926053d926f89a (patch) | |
tree | cb368959a2004a8860f030c4a3c2f460abc5c28b /source/pyAggr3g470r.py | |
parent | Updated revision date. (diff) | |
download | newspipe-33ef607cecb94f325ceb31d4f4926053d926f89a.tar.gz newspipe-33ef607cecb94f325ceb31d4f4926053d926f89a.tar.bz2 newspipe-33ef607cecb94f325ceb31d4f4926053d926f89a.zip |
It's even better with defaultdict
Diffstat (limited to 'source/pyAggr3g470r.py')
-rwxr-xr-x | source/pyAggr3g470r.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py index c0807bce..ac4c5998 100755 --- a/source/pyAggr3g470r.py +++ b/source/pyAggr3g470r.py @@ -44,6 +44,8 @@ import os import re import datetime +from collections import defaultdict + import cherrypy from mako.template import Template from mako.lookup import TemplateLookup @@ -466,8 +468,7 @@ class pyAggr3g470r(object): for feed in feeds: for article in self.mongo.get_articles(feed["feed_id"]): language = guess_language_name(utils.clear_string(article["article_content"])) - result.setdefault(language, {}) - result[language].setdefault(feed["feed_id"], []) + result.setdefault(language, defaultdict(list)) result[language][feed["feed_id"]].append(article) tmpl = lookup.get_template("languages.html") return tmpl.render(articles_sorted_by_languages=result, mongo=self.mongo) |