python 将列表拆分为大小均匀的块

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 将列表拆分为大小均匀的块相关的知识,希望对你有一定的参考价值。

# https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python
l = range(1, 1000)

def chunks(l, n):
    # Yield successive n-sized chunks from l
    for i in xrange(0, len(l), n):
        yield l[i:i + n]

import pprint
pprint.pprint(list(chunks(range(10, 75), 10)))

以上是关于python 将列表拆分为大小均匀的块的主要内容,如果未能解决你的问题,请参考以下文章