views:

4094

answers:

1

Let's say, as an example, I have the following list:

foo = ['a', 'b', 'c', 'd', 'e']

What is the best way to retrieve an item at random from this list?

+46  A: 
foo = ['a', 'b', 'c', 'd', 'e']
from random import choice
print choice(foo)
Pēteris Caune
This is why I love python.
Agos