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

@@ -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: