python: use the setdefault method on dict
It allows more concise code and skips some key lookups.
This commit is contained in:
@@ -87,10 +87,7 @@ def index_by(objects, *funcs):
|
||||
result = {}
|
||||
for o in objects:
|
||||
key = f(o)
|
||||
if key not in result:
|
||||
result[key] = [o]
|
||||
else:
|
||||
result[key].append(o)
|
||||
result.setdefault(key, []).append(o)
|
||||
|
||||
for key, objects in result.items():
|
||||
result[key] = index_by(objects, *funcs[1:])
|
||||
|
Reference in New Issue
Block a user