index_by supports compound index keys.
This commit is contained in:
parent
72c753b93e
commit
e15316e825
@ -68,6 +68,12 @@ def index_by(objects, *funcs):
|
|||||||
|
|
||||||
index1 = index_by(list_of_specs, 'arch', 'compiler')
|
index1 = index_by(list_of_specs, 'arch', 'compiler')
|
||||||
index2 = index_by(list_of_specs, 'compiler')
|
index2 = index_by(list_of_specs, 'compiler')
|
||||||
|
|
||||||
|
You can also index by tuples by passing tuples:
|
||||||
|
|
||||||
|
index1 = index_by(list_of_specs, ('arch', 'compiler'))
|
||||||
|
|
||||||
|
Keys in the resulting dict will look like ('gcc', 'bgqos_0').
|
||||||
"""
|
"""
|
||||||
if not funcs:
|
if not funcs:
|
||||||
return objects
|
return objects
|
||||||
@ -75,6 +81,8 @@ def index_by(objects, *funcs):
|
|||||||
f = funcs[0]
|
f = funcs[0]
|
||||||
if isinstance(f, basestring):
|
if isinstance(f, basestring):
|
||||||
f = lambda x: getattr(x, funcs[0])
|
f = lambda x: getattr(x, funcs[0])
|
||||||
|
elif isinstance(f, tuple):
|
||||||
|
f = lambda x: tuple(getattr(x, p) for p in funcs[0])
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
for o in objects:
|
for o in objects:
|
||||||
|
Loading…
Reference in New Issue
Block a user