From e15316e8256175359ef38066900df45b8b4d126c Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 1 Dec 2014 23:13:09 -0800 Subject: index_by supports compound index keys. --- lib/spack/llnl/util/lang.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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: -- cgit v1.2.3-70-g09d2