Ray Vega Ray Vega - 11 months ago 75
Python Question

How do I randomly select an item from a list using Python?

Assume I have the following list:

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

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


Use random.choice:

import random

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