Q:

Write a Python program to extract a given number of randomly selected elements from a given list

0

Write a Python program to extract a given number of randomly selected elements from a given list

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import random
def random_select_nums(n_list, n):
        return random.sample(n_list, n)
n_list = [1,1,2,3,4,4,5,1]
print("Original list:") 
print(n_list)
selec_nums = 3
result = random_select_nums(n_list, selec_nums)
print("\nSelected 3 random numbers of the above list:")
print(result)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now