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:
@@ -140,8 +140,7 @@ class UnicodeWriter(object):
|
||||
self.queue.truncate(0)
|
||||
|
||||
def writerows(self, rows):
|
||||
for row in rows:
|
||||
self.writerow(row)
|
||||
map(self.writerow, rows)
|
||||
|
||||
def close(self):
|
||||
self.stream.close()
|
||||
@@ -253,8 +252,8 @@ class CSVWriter(object):
|
||||
if not option_box.cfilter.is_empty():
|
||||
self.db = gen.proxy.FilterProxyDb(self.db, option_box.cfilter)
|
||||
|
||||
for p in self.db.iter_person_handles():
|
||||
self.plist[p] = 1
|
||||
self.plist.update([p, 1] for p in self.db.iter_person_handles())
|
||||
|
||||
# get the families for which these people are spouses:
|
||||
self.flist = {}
|
||||
for key in self.plist:
|
||||
|
@@ -174,8 +174,7 @@ class GeneWebWriter(object):
|
||||
if not option_box.cfilter.is_empty():
|
||||
self.db = gen.proxy.FilterProxyDb(self.db, option_box.cfilter)
|
||||
|
||||
for p in self.db.iter_person_handles():
|
||||
self.plist[p] = 1
|
||||
self.plist.update([p, 1] for p in self.db.iter_person_handles())
|
||||
|
||||
self.flist = {}
|
||||
for key in self.plist:
|
||||
|
@@ -144,13 +144,13 @@ class CalendarWriter(object):
|
||||
self.option_box.parse_options()
|
||||
|
||||
if self.option_box.cfilter is None:
|
||||
for p in self.db.iter_person_handles():
|
||||
self.plist[p] = 1
|
||||
self.plist.udpate([p, 1]
|
||||
for p in self.db.iter_person_handles())
|
||||
else:
|
||||
try:
|
||||
for p in self.option_box.cfilter.apply(self.db,
|
||||
self.db.iter_person_handles()):
|
||||
self.plist[p] = 1
|
||||
self.plist.update([p, 1]
|
||||
for p in self.option_box.cfilter.apply(
|
||||
self.db, self.db.iter_person_handles()))
|
||||
except Errors.FilterError, msg:
|
||||
(m1, m2) = msg.messages()
|
||||
ErrorDialog(m1, m2)
|
||||
|
@@ -158,8 +158,7 @@ class CardWriter(object):
|
||||
self.oldval = newval
|
||||
|
||||
def cl_setup(self):
|
||||
for p in self.db.iter_person_handles():
|
||||
self.plist[p] = 1
|
||||
self.plist.update([p, 1] for p in self.db.iter_person_handles())
|
||||
|
||||
def writeln(self, text):
|
||||
#self.g.write('%s\n' % (text.encode('iso-8859-1')))
|
||||
|
@@ -1078,8 +1078,7 @@ class GrampsXmlWriter(UpdateCallback):
|
||||
self.g.write('%s<coord long="%s" lat="%s"/>\n'
|
||||
% (" "*(index+1), longitude, lat))
|
||||
self.dump_location(main_loc)
|
||||
for loc in place.get_alternate_locations():
|
||||
self.dump_location(loc)
|
||||
map(self.dump_location, place.get_alternate_locations())
|
||||
self.write_media_list(place.get_media_list(), index+1)
|
||||
self.write_url_list(place.get_url_list())
|
||||
self.write_note_list(place.get_note_list(), index+1)
|
||||
|
Reference in New Issue
Block a user