diff options
Diffstat (limited to 'lib/spack/llnl/util/lang.py')
-rw-r--r-- | lib/spack/llnl/util/lang.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/spack/llnl/util/lang.py b/lib/spack/llnl/util/lang.py index f1a0b7ba31..51bd710ddb 100644 --- a/lib/spack/llnl/util/lang.py +++ b/lib/spack/llnl/util/lang.py @@ -1022,6 +1022,14 @@ def stable_partition( return true_items, false_items +def ensure_last(lst, *elements): + """Performs a stable partition of lst, ensuring that ``elements`` + occur at the end of ``lst`` in specified order. Mutates ``lst``. + Raises ``ValueError`` if any ``elements`` are not already in ``lst``.""" + for elt in elements: + lst.append(lst.pop(lst.index(elt))) + + class TypedMutableSequence(MutableSequence): """Base class that behaves like a list, just with a different type. |