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. Another solution is this: shuffled_numbers = random.sample(range(10, 10 ** 5), k=len(range(10, 10 ** 5))) This is better because it solves the 2 points above. However, it is quite cumbersome. I notice that the `random.sample` function doesn't have a default behavior set when you don't specify `k`. This is fortunate, because we could make that behavior just automatically take the length of the first argument. So we could do this: shuffled_numbers = random.sample(range(10, 10 ** 5)) What do you think? Thanks, Ram.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@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/OHLXVKIBMNSQO6BCFK6LEHSYNXDB6OQJ/ Code of Conduct: http://python.org/psf/codeofconduct/