将一个列表切分成多个小列表

将一个列表切分成多个小列表

# -*- coding: utf-8 -*-
"""
@Time    : 2021/7/20 11:34
@Author  : Little Duo
@File    : Tools.py
"""

def splitList(oldList, sonListLen):
    """
    将一个列表切分成多个小列表

    @param oldList: 列表
    @param sonListLen: 每个小列表的长度
    @return:
    """
    list_of_group = zip(*(iter(oldList),) * sonListLen)
    newList = [list(i) for i in list_of_group]
    count = len(oldList) % sonListLen
    newList.append(oldList[-count:]) if count != 0 else newList
    return newList
posted @ 2023-02-28 14:33  LittleDuo  阅读(24)  评论(0)    收藏  举报