How can I randomly pick an element from a Python list?

I’m working on a small Python script and need a simple way to python choose random from list values. I have a list of items, and each time the code runs, I want to retrieve one element at random.

Right now, I’m just dealing with a basic list, but I’m not sure what the cleanest or most Pythonic way is to randomly select a single item from it.

Here’s a simplified version of what I have (rewritten example):

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

What’s the recommended way to randomly choose one element from this list? Also, are there any important things to keep in mind (like performance or randomness quality) when doing this in Python?

Any advice or examples would be appreciated. Thanks!

If all you need is a single random element from a list, Python’s built-in random module has exactly what you want. I use this all the time for quick scripts:

import random

items = ['a', 'b', 'c', 'd', 'e']
picked_item = random.choice(items)
print("Randomly selected:", picked_item)

This is straightforward, readable, and works perfectly for lists of any size. I usually go with this method unless I have some special requirement, like needing reproducible random results, in which case you can also set a seed with random.seed()

Sometimes, for learning purposes or if I want more control over the index, I use random.randint to pick a random index myself:

import random

items = ['a', 'b', 'c', 'd', 'e']
index = random.randint(0, len(items) - 1)
picked_item = items[index]
print("Randomly selected:", picked_item)

This gives you the same result as random.choice but lets you see what’s happening under the hood. I’ve used this approach in a few tutorials when explaining randomness to beginners. It’s also handy if you want to do extra operations with the index itself.

If later you want to pick more than one element or avoid picking the same item twice, random.sample is really useful:

import random

items = ['a', 'b', 'c', 'd', 'e']
picked_items = random.sample(items, 2)
print("Randomly selected two items:", picked_items)

I often use this when I need to randomly select multiple unique elements, like shuffling a subset of data. It’s efficient and guarantees you won’t get duplicates, which choice alone won’t do if you call it multiple times. For a single random item, random.choice is the most Pythonic and readable. If you want the index too or are teaching randomness concepts, randint works. For multiple selections without repetition, go with random.sample.