splitlist分隔与列表拆分

"""
   列表拆分示例程序,这个程序可以按数量拆分列表
"""

def splitlist(biglist,number):
    """number是要分成的份数"""
    retlist=[]
    listlen=len(biglist)
    everyamounts=listlen//number
    slicelist=[]
    for i in range(number):
        start=i*everyamounts
        end=(i+1)*everyamounts
        if i==(number-1):          #加这句是让最后的列表把剩余的也包括进去。
            end=listlen
        slicelist=biglist[start:end]
        retlist.append(slicelist)
    return retlist

You must log in to read the rest of this article. Please log in or register as a user.