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:
Gerald Britton
2010-01-25 17:45:21 +00:00
parent fbb8fa2a52
commit 8f0582df8a
49 changed files with 125 additions and 188 deletions

View File

@@ -225,8 +225,8 @@ class FamilyView(ListView):
_('_Delete Item'), _('Cancel'))
if q.run():
self.uistate.set_busy_cursor(1)
for handle in self.selected_handles():
self.dbstate.db.remove_family_relationships(handle)
map(self.dbstate.db.remove_family_relationships,
self.selected_handles())
self.build_tree()
self.uistate.set_busy_cursor(0)

View File

@@ -2039,8 +2039,7 @@ class GeoView(HtmlView):
self.vbox.destroy()
except: # pylint: disable-msg=W0704
pass # pylint: disable-msg=W0702
for child in self.hpaned.get_children(): # cleanup
self.hpaned.remove(child)
map(self.hpaned.remove, self.hpaned.get_children())
self.vbox = gtk.VBox()
self.hpaned.pack_start(self.vbox, True, True)
self.filter_sidebar = filter_class(self.dbstate, self.uistate,

View File

@@ -1241,11 +1241,8 @@ class GrampletView(PageView):
qr_menu = rg_menu.get_submenu()
if qr_menu is not None:
rg_menu.remove_submenu()
names = []
for gramplet in self.closed_gramplets:
names.append(gramplet.title)
for opts in self.closed_opts:
names.append(opts["title"])
names = [gramplet.title for gramplet in self.closed_gramplets]
names.extend(opts["title"] for opts in self.closed_opts)
names.sort()
if len(names) > 0:
qr_menu = gtk.Menu()

View File

@@ -405,10 +405,8 @@ class RelationshipView(NavigationView):
#reset the connects
self._change_db(db)
if self.child:
for old_child in self.vbox.get_children():
self.vbox.remove(old_child)
for old_child in self.header.get_children():
self.header.remove(old_child)
map(self.vbox.remove, self.vbox.get_children())
map(self.header.remove, self.header.get_children())
self.child = None
self.bookmarks.update_bookmarks(db.get_bookmarks())
if self.active:
@@ -547,9 +545,7 @@ class RelationshipView(NavigationView):
def write_title(self, person):
for old_child in self.header.get_children():
self.header.remove(old_child)
map(self.header.remove, self.header.get_children())
table = gtk.Table(2, 3)
table.set_col_spacings(12)
table.set_row_spacings(0)