Re: How to pop random item from a list?

2006-03-11 Thread Andrew Gwozdziewycz
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

Re: How to pop random item from a list?

2006-03-10 Thread Peter Otten
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

Re: How to pop random item from a list?

2006-03-10 Thread flamesrock
Thanks guys! :D -- http://mail.python.org/mailman/listinfo/python-list

How to pop random item from a list?

2006-03-09 Thread flamesrock
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

Re: How to pop random item from a list?

2006-03-09 Thread marduk
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))) --

Re: How to pop random item from a list?

2006-03-09 Thread Ben Cartwright
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