[Python-ideas] About adding a new iterator methodcalled"shuffled"
Raymond Hettinger
python at rcn.com
Tue Mar 24 23:20:39 CET 2009
> Note that using sorting to shuffle is likely very inefficient.
Who cares? The OP's goal was to save a few programmer
clock cycles so he could in-line what we already get from
random.shuffle(). His request is use case challenged
(very few programs would benefit and those would only
save a line or two). If he actually cares about O(n) time
then it's trivial to write:
s = list(iterable)
random.shuffle(s)
for elem in s:
. . .
But if he want's to mush it on one-line, I gave a workable
alternative.
Raymond
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090324/30d9edc4/attachment.html>
More information about the Python-ideas
mailing list