Home > Article > Backend Development > How to randomly select elements from a list in python
Below I will share with you a method of randomly selecting elements from a list in python. It has certain reference value and I hope it can be helpful to everyone.
Randomly select elements from list random.sample
##
import random a = [1, 2, 3, 4, 5, 6, 7, 8, 9] b = random.sample(a, 5)Related recommendations:
How to achieve mutual conversion from str to list in python
The above is the detailed content of How to randomly select elements from a list in python. For more information, please follow other related articles on the PHP Chinese website!