How to Randomly Select an Item from a List in Python?

Spread the love

Problem –

You want to randomly select an item from a list in python.

Solution –

To randomly select an item from a list use the random.choice() function.

In [1]: lst = [5, 10, 15, 20, 25, 30 ] 

In [2]: import random

In [3]: random.choice(lst)
Out[3]: 15

Rating: 1 out of 5.

Leave a Reply