[Tutor] How to pull a random element from a list?
ak@silmarill.org
ak@silmarill.org
Wed, 25 Jul 2001 08:19:35 -0400
On Wed, Jul 25, 2001 at 12:03:39PM +0100, alan.gauld@bt.com wrote:
> > I'm trying to figure out how the heck to pull an element from
> > a list or dictionary at random. I have a list of words and
> > need to be able to pull one at random.
>
> One way is to pull my guessing game object framework
> from Useless Python. It includes the code for selecting
> a random word from a list(which is read from a file).
>
> The essence is to generate a random integer between
> 0 and len(list)-1
>
> randint() is your friend.
>
> Alan G
Isn't it easier to use random.choice()? Are there any
advantages to this method i'm missing?
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: http://silmarill.org/cymbaline