avatar

python列表随机打乱顺序
import random
n=eval(input())
m=list(range(1,n+1))
print ("随机排序列表 : ", list)
for i in range(0,n):
random.shuffle(m) # shuffle函数是将原list打乱而不是返回一个新的list
for j in range(0,n):
print(m[j],end=' ')
print()
Author: Michelle19l
Link: https://gitee.com/michelle19l/michelle19l/2020/05/25/list打乱/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Donate
  • 微信
    微信
  • 支付寶
    支付寶