USES the python random module’s choice method to randomly select an element
foo = ['a', 'b', 'c', 'd', 'e']
from random import choice
print choice(foo)
USES the python random module’s sample function to randomly select a set of elements from the list
list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
slice = random.sample(list, 5) #从list中随机获取5个元素,作为一个片断返回
print slice
print list #原有序列并没有改变。
div>
Read More:
- 26 English letters in upper and lower case and 0-9 to generate 8-bit random password
- R language notes – sample() function
- Python uses the priority queue to get the maximum k elements
- From in Python__ future__ The role of import *
- java.util.Collections.max() [How to Use]
- Pre initialization of list content and length in Python
- Global variable error: unboundlocalerror: local variable ‘l’ referenced before assignment
- python keyerror(0)
- Django. Using f () to solve the competition problem
- numpy.random.rand()
- Type error: sequence item 0: expected STR instance, int found
- Install in Python 3. X web.py
- Tensorflow image random_ There seems to be something wrong with the shift function
- Python: Understanding__ str__
- Random forest algorithm learning
- Typeerror: ‘module’ object is not callable
- Typeerror: write() argument must be STR, not bytes and the method of writing binary file in Python 3
- The problem of “value error: zero length field name in format” in Python 2.6.6 of CentOS 6.9
- Implement Set using Array.
- Typeerror: write() argument must be STR, not bytes and the method of writing binary file in Python 3