python - random.shuffle有序列表乱序排列
Python 排列 Random shuffle 乱序
2023-09-27 14:29:10 时间
python - 使用random.shuffle()将有序列表进行乱序排列
代码如下:
>>> import random
>>> li = range(20)
>>> li
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
>>> random.shuffle(li)
>>> li
[4, 17, 0, 13, 8, 9, 19, 10, 2, 18, 5, 15, 1, 12, 14, 3, 16, 11, 6, 7]
>>>
如图:
相关文章
- python基础练习 特殊回文数
- python 高级篇--Exception的语法操作
- 第51天: Python Queue 入门
- Web自动化测试Python+Selenium环境搭建
- 学 Python 好不好就业?爬了招聘网站后给你答案
- python 技巧 之 pyCharm快速添加第三方库和插件
- python学习实例(2)
- Python 递归函数
- (十二)判断Python中变量是否是函数
- 成功解决:Can‘t find Python executable “python“, you can set the PYTHON env variable.
- python nose测试框架全面介绍十---用例的跳过
- Python开发环境搭建
- PyQt(Python+Qt)学习随笔:QMainWindow的tabifyDockWidget方法将QDockWidget两个停靠窗选项卡式排列
- PyQt(Python+Qt)学习随笔:QTreeWidgetItem项是否禁用disable、隐藏isHidden和允许选中isSelected
- Python time模块学习
- python - os模块的应用
- python 获取某月的第一天零点和最后一天的时间