python 字典Chunker

Posted

tags:

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

def chunk_dict(data, chunk_size):
    """
    Yield successive n-sized chunks from l.
    https://stackoverflow.com/a/22878842
    :param data: the dictionary we'll chunk
    :param chunk_size: the size of the chunks that we'll create.
    :return: the dictionary chunks.
    """
    it = iter(data)
    for i in range(0, len(data), chunk_size):
        yield {k: data[k] for k in islice(it, chunk_size)}

以上是关于python 字典Chunker的主要内容,如果未能解决你的问题,请参考以下文章

Could not initialize English chunker/Could not load file from classpath: ‘/en-token.bin‘

python-字典

python3字典遍历

python字典/字典的键值/字典属性的添加

python 18:字典的赋值

python中字典的问题