Trying to use sets for random selection, but the pop() method returns items in order

Carl Banks pavlovevidence at gmail.com
Wed Jul 1 21:29:21 EDT 2009


On Jul 1, 5:49 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Carl Banks <pavlovevide... at gmail.com> writes:
> > Instead, call random.shuffle() on the list, and iterate through that
> > to get the elements in random order.
>
> It's better to use random.sample() than random.shuffle().

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.


Aren't-absolutist-opinions-cool?-ly yr's,

Carl Banks



More information about the Python-list mailing list