How to pop random item from a list?

Ben Cartwright bencvt at gmail.com
Fri Mar 10 01:49:34 EST 2006


flamesrock wrote:
> whats the best way to pop a random item from a list??

  import random
  def popchoice(seq):
        # raises IndexError if seq is empty
        return seq.pop(random.randrange(len(seq)))

--Ben




More information about the Python-list mailing list