最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Python如何将一个数组均分为多个数组 Python将一个数组均分为多个数组实例
时间:2019-11-07 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下Python将一个数组均分为多个数组实例,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
将一个数组,均分为多个数组
代码
# -*- coding:utf-8 -*- # py3 def list_split(items, n): return [items[i:i+n] for i in range(0, len(items), n)] if '__main__' == __name__: list1 = ['s1', 's2', 's3', 's4', 's5', 's6', 's7'] list2 = list_split(list1, 3) print(list2)
输出
[['s1', 's2', 's3'], ['s4', 's5', 's6'], ['s7']]
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27