On Jul 1, 6:37 pm, Paul Rubin <http://[email protected]> wrote:
> Carl Banks <[email protected]> writes:
> > If you're iterating through the whole list and don't need to preserve
> > the original order (as was the case here) random.shuffle() is better.
>
> 1. Random.sample avoids iterating through the whole list when it can.
>
> 2. Say you want to choose 10 random numbers between 1 and 1000000.
>
>    random.sample(xrange(1000000), 10)
>
> works nicely.  Doing the same with shuffle is painful.

random.shuffle() is still better when you're iterating through the
whole list as the OP was doing.

Carl Banks
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to