diff --git a/collections_extended/setlists.py b/collections_extended/setlists.py index 8e759fa..f97c7a4 100644 --- a/collections_extended/setlists.py +++ b/collections_extended/setlists.py @@ -432,6 +432,12 @@ def remove_all(self, elems_to_delete): """ self._delete_all(elems_to_delete, raise_errors=True) + def reverse(self): + """Reverse the setlist in-place.""" + self._list.reverse() + for index, item in enumerate(self._list): + self._dict[item] = index + # Implement MutableSet def add(self, item): diff --git a/tests/test_setlists.py b/tests/test_setlists.py index 20b1298..3c05ad2 100644 --- a/tests/test_setlists.py +++ b/tests/test_setlists.py @@ -596,3 +596,9 @@ def test_swap(): sl.swap(-1, 1) assert_internal_structure(sl) assert sl == setlist('afbdec') + + +def test_reverse(): + sl = setlist('abcdef') + sl.reverse() + assert sl == setlist('fedcba')