diff --git a/magic_list/prelude.py b/magic_list/prelude.py index 18d6473..6b560e2 100644 --- a/magic_list/prelude.py +++ b/magic_list/prelude.py @@ -152,13 +152,8 @@ def shuffled(self) -> typing_extensions.Self: [] """ - result = self.__class__() - - while len(result) != len(self): - item = random.choice(self) - - if item not in result: - result.append(item) + result = self.copy() + random.shuffle(result) return result diff --git a/tests/list_test.py b/tests/list_test.py index 3797c69..bdd2189 100644 --- a/tests/list_test.py +++ b/tests/list_test.py @@ -234,8 +234,8 @@ def test_sorted_ok(prebuild_list, kwargs, result): @pytest.mark.parametrize( ["prebuild_list", "result"], [ - ["list_int_filled", list((-1, 3, 20, 5))], - ["list_str_filled", list(("ciao", "hello", "holá", "bonjour"))], + ["list_int_filled", list((20, 3, 5, -1))], + ["list_str_filled", list(('holá', 'hello', 'bonjour', 'ciao'))], ["list_empty", list()], ], indirect=["prebuild_list"],