Use built-in functions to replace for loops:
Old code: for x in y: f(x) New Code: map(f, y) Also use defaultdict instead of simple dict when advantageous and use list comprehensions instead of for loops where map() could be used but requires lambdas. svn: r14135
This commit is contained in:
@@ -34,6 +34,7 @@ from gen.lib import Person
|
||||
import DateHandler
|
||||
|
||||
import posixpath
|
||||
from collections import defaultdict
|
||||
from gen.ggettext import sgettext as _
|
||||
from gen.ggettext import ngettext
|
||||
|
||||
@@ -133,12 +134,12 @@ def run(database, document, filter_name, *args, **kwargs):
|
||||
stab.row(family)
|
||||
matches += 1
|
||||
elif (filter_name == 'unique surnames'):
|
||||
namelist = {}
|
||||
namelist = defaultdict(int)
|
||||
for person in database.iter_people():
|
||||
names = [person.get_primary_name()] + person.get_alternate_names()
|
||||
surnames = list(set([name.get_group_name() for name in names]))
|
||||
for surname in surnames:
|
||||
namelist[surname] = namelist.get(surname, 0) + 1
|
||||
namelist[surname] += 1
|
||||
stab.columns(_("Surname"), _("Count"))
|
||||
for name in sorted(namelist):
|
||||
stab.row(name, namelist[name])
|
||||
|
@@ -315,7 +315,7 @@ class AllRelReport():
|
||||
if isinstance(fam, list):
|
||||
famstr = str(fam[0]+1)
|
||||
for val in fam[1:] :
|
||||
famstr = famstr + ', ' + str(val+1)
|
||||
famstr += ', ' + str(val+1)
|
||||
else:
|
||||
famstr = str(fam+1)
|
||||
sdoc.paragraph(_FMT_DET2 % (' ', par_str, birth_str, famstr))
|
||||
@@ -335,7 +335,6 @@ class AllRelReport():
|
||||
sdoc.paragraph("")
|
||||
sdoc.paragraph(_("The following problems were encountered:"))
|
||||
|
||||
for msg in msg_list :
|
||||
sdoc.paragraph(msg)
|
||||
map(sdoc.paragraph, msg_list)
|
||||
sdoc.paragraph("")
|
||||
sdoc.paragraph("")
|
||||
|
Reference in New Issue
Block a user