
I submitted a patch now, but Serhiy showed me that it's already been proposed before, and rejected by Raymond Hettinger and Terry Reedy in issues 26393 and 27964. On Sun, Aug 2, 2020 at 8:05 AM Steven D'Aprano <steve@pearwood.info> wrote:
On Sat, Aug 01, 2020 at 08:54:16PM +0300, Ram Rachum wrote:
When writing some code now, I needed to produce a shuffled version of `range(10, 10 ** 5)`.
This is one way to do it:
shuffled_numbers = list(range(10, 10 ** 5)) random.shuffle(shuffled_numbers)
I don't like it because (1) it's too imperative and (2) I'm calling the list "shuffled" even before it's shuffled.
This is easily solved with a three-line helper:
def shuffled(iterable): L = list(iterable) random.shuffle(L) return L
I have implemented this probably a half a dozen times, and I expect others have too. I agree with Alex that this would make a nice addition to the random module.
-- Steven _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/47JMNM... Code of Conduct: http://python.org/psf/codeofconduct/