On Mar 11, 2006, at 11:21 AM, Peter Otten wrote:
Am Freitag, 10. März 2006 19:38 schrieben Sie:
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.
This brings up
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
--
http://mail.python.org/mailman/listinfo/python-list
Thanks guys! :D
--
http://mail.python.org/mailman/listinfo/python-list
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??
-Thanks
--
http://mail.python.org/mailman/listinfo/python-list
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)))
--
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
--
http://mail.python.org/mailman/listinfo/python-list