Randomly Select Element From List in Python Using choices()

(Last Updated On: 03/03/2023)

Python Program to Randomly Select Elements From List Using choices()

# Randomly Select an more than Element From the List using choices() in python

# importing random module
import random

# declaring list
list = ['a', 'b', 'c', 'd', 'e', 'f']

# initializing the value of n
n = 4

# printing n elements from list
print(random.choices(list, k=n))


['b', 'a', 'c', 'c']

Leave a Reply

Your email address will not be published. Required fields are marked *