Python怎么使用random.shuffle()随机打乱字典排序(python,random.shuffle(),开发技术)

时间:2024-05-05 06:51:47 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

    Python%E6%80%8E%E4%B9%88%E4%BD%BF%E7%94%A8random.shuffle%28%29%E9%9A%8F%E6%9C%BA%E6%89%93%E4%B9%B1%E5%AD%97%E5%85%B8%E6%8E%92%E5%BA%8F

运行结果:

[[1], [2], [5], [0], [7], [9], [3], [8], [4], [6]]
[[6], [0], [7], [1], [3], [9], [5], [2], [4], [8]]

运行结果:

{'channelCode': 'AppStore', 'productCode': 'xyd', 'appType': 'ios', 'event': 'FORGET_PWD', 'account': 'phone'}
{'event': 'FORGET_PWD', 'account': 'phone', 'productCode': 'xyd', 'appType': 'ios', 'channelCode': 'AppStore'}

有时候,我们需要将列表中的元素随机打乱顺序,其实只需要使用random库提供的shuffle方法即可,不需要自己额外编写函数。

importrandom

输出:

[9, 5, 2, 8, 6, 7, 1, 10, 4, 3]
Process finished with exit code 0

注意,shuffle方法没有返回值,不会生成新的列表,只是将原列表的顺序随机打乱。

本文:Python怎么使用random.shuffle()随机打乱字典排序的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:怎么用python读取Windows注册表下一篇:

12 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18