summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2014-12-01 23:13:09 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2014-12-01 23:13:09 -0800
commite15316e8256175359ef38066900df45b8b4d126c (patch)
treeaa168db3ccd1930075159bdd34e956b669e4d848
parent72c753b93e368441ba7fd281c74886c5e52a820c (diff)
downloadspack-e15316e8256175359ef38066900df45b8b4d126c.tar.gz
spack-e15316e8256175359ef38066900df45b8b4d126c.tar.bz2
spack-e15316e8256175359ef38066900df45b8b4d126c.tar.xz
spack-e15316e8256175359ef38066900df45b8b4d126c.zip
index_by supports compound index keys.
-rw-r--r--lib/spack/llnl/util/lang.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/spack/llnl/util/lang.py b/lib/spack/llnl/util/lang.py
index ce7d0197f0..049d158c6d 100644
--- a/lib/spack/llnl/util/lang.py
+++ b/lib/spack/llnl/util/lang.py
@@ -68,6 +68,12 @@ def index_by(objects, *funcs):
index1 = index_by(list_of_specs, 'arch', '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:
return objects
@@ -75,6 +81,8 @@ def index_by(objects, *funcs):
f = funcs[0]
if isinstance(f, basestring):
f = lambda x: getattr(x, funcs[0])
+ elif isinstance(f, tuple):
+ f = lambda x: tuple(getattr(x, p) for p in funcs[0])
result = {}
for o in objects: