[Python-Dev] About adding a new iterator method called "shuffled"

Roy Hyunjin Han starsareblueandfaraway at gmail.com
Tue Mar 24 16:48:14 CET 2009


I know that Python has iterator methods called "sorted" and "reversed" and
these are handy shortcuts.


Why not add a new iterator method called "shuffled"?

>>> for x in shuffled(range(5)):
>>>    print x
>>> 3
>>> 1
>>> 2
>>> 0
>>> 4


Currently, a person has to do the following because random.shuffle() does
not return the actual shuffled list.  It is verbose.

>>> import random
>>> x = range(5)
>>> random.shuffle(x)
>>> for x in x:
>>>     print x
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20090324/65b05c4e/attachment-0001.htm>


More information about the Python-Dev mailing list