[Python-ideas] [Python-Dev] About adding a new iterator methodcalled "shuffled"

Antoine Pitrou solipsis at pitrou.net
Tue Mar 24 19:29:56 CET 2009


Raymond Hettinger <python at ...> writes:
> 
> You can already write:
> 
>        sorted(s, key=lambda x: random())
> 
> But nobody does that.  So you have a good
> indication that the proposed method isn't need.

On the other hand, sorting is O(n.log(n)), which is probably sub-optimal for
shuffling (I don't know how shuffle() is internally implemented, but ISTM that
it shouldn't take more than O(n)).

Note that I'm not supporting the original proposal: shuffle() is not used enough
to warrant such a shortcut.

Regards

Antoine.





More information about the Python-ideas mailing list