How to pop random item from a list?

marduk usenet at marduk.letterboxes.org
Fri Mar 10 01:12:33 EST 2006


On Thu, 2006-03-09 at 21:59 -0800, flamesrock wrote:
> Hi,
> 
> It's been a while since I've played with python.
> 
> My question is... whats the best way to pop a random item from a list??

import random
# ...

item = mylist.pop(random.randint(0,len(mylist)))





More information about the Python-list mailing list