Python shuffle() function
Description
shuffle() The method randomly shuffles all elements of a sequence.
Syntax
The syntax of the shuffle() method is as follows:
import random
random.shuffle (lst )
**Note:** shuffle() cannot be accessed directly; you need to import the random module and then call the method through the random static object.
Parameters
- lst -- can be a list.
Return Value
This function has no return value.
Example
The following shows examples of using the shuffle() method:
Example
#!/usr/bin/python
-- coding: UTF-8 --
import
random
list
=
[
20
,
16
,
10
,
5
]
random
.
shuffle
(
list
)
"Randomly shuffled list: "
,
list
random
.
shuffle
(
list
)
"Randomly shuffled list: "
,
list
Running the example above produces:
随机排序列表 : [16, 5, 10, 20]
随机排序列表 : [16, 5, 20, 10]
Python Numbers