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:
- Python uses the priority queue to get the maximum k elements
- Random number random reports an error. Illegalargumentexception: bound must be positive
- valueError: Length mismatch: Expected axis has 40 elements, new values have 38 elements
- 26 English letters in upper and lower case and 0-9 to generate 8-bit random password
- numpy.random.rand()
- Random forest algorithm learning
- Tensorflow image random_ There seems to be something wrong with the shift function
- Matlab: Three forms of random number generated (Rand, Randi and Randn)
- Selenium: 8 Ways to Locate Elements
- Arthas selects PID error and port occupancy error
- Out of bag error in Random Forest
- Solve the unmarshalling error: unexpected element (URI: “local:” name “). Expected elements are
- Remove array duplicate elements
- V-for styles individual elements
- Mybatis custom list collection parser
- JQuery is a solution to the disappearance of listening events after adding elements with append
- Several ways to center elements horizontally and vertically
- P – Random Teams
- Can’t find Python executable “D:\python3\python.exe”, you can set the PYTHON env variable.
- “Not a valid NDK directory” appears when eclipse ADT selects the NDK directory