Python Program - Randomly Select an Element From the List

Here's a Python program to randomly select an element from a list:

import random

my_list = [1, 2, 3, 4, 5]
random_element = random.choice(my_list)

print("Random element from the list:", random_element)
Source:‮igi.www‬ftidea.com

The random.choice() function is used to randomly select an element from a list. It takes a sequence (in this case, the list my_list) as an argument and returns a randomly chosen element from it.

Note that the random module needs to be imported at the beginning of the program in order to use the random.choice() function.