How to randomly select elements from a list in python

不言
Release: 2018-04-09 09:27:32
Original
4841 people have browsed it

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!