thelist = ['a','b','c','d']
Run Code Online (Sandbox Code Playgroud)
我怎么能用Python加扰它们?
Pet*_*ter 16
>>> import random
>>> thelist = ['a', 'b', 'c', 'd']
>>> random.shuffle(thelist)
>>> thelist
['d', 'a', 'c', 'b']
Run Code Online (Sandbox Code Playgroud)
你的结果(希望!)会有所不同.
Phi*_*hil 15
import random
random.shuffle(thelist)
Run Code Online (Sandbox Code Playgroud)
请注意,这会将列表原位洗牌.
使用模块中的shuffle功能random:
>>> from random import shuffle
>>> thelist = ['a','b','c','d']
>>> shuffle(thelist)
>>> thelist
['c', 'a', 'b', 'd']
Run Code Online (Sandbox Code Playgroud)