How to pop random item from a list?

Peter Otten __peter__ at web.de
Fri Mar 10 09:28:35 CET 2006


marduk wrote:

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

This is broken because randint(a, b) may return b.
I prefer randrange(len(mylist)) over randint(0, len(mylist)-1) as a fix.

Peter




More information about the Python-list mailing list