网络编程
位置:首页>> 网络编程>> Python编程>> Python 切分数组实例解析

Python 切分数组实例解析

作者:人的影  发布时间:2022-04-15 02:45:05 

标签:python,切分,数组

这篇文章主要介绍了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']]

来源:https://www.cnblogs.com/eoalfj/p/11810856.html

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com