Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python split dict into chunks

# Since the dictionary is so big, it would be better to keep
# all the items involved to be just iterators and generators, like this

from itertools import islice

def chunks(data, SIZE=10000):
    it = iter(data)
    for i in range(0, len(data), SIZE):
        yield {k:data[k] for k in islice(it, SIZE)}
        
# Sample run:
for item in chunks({i:i for i in range(10)}, 3):
    print item
    
# Output
# {0: 0, 1: 1, 2: 2}
# {3: 3, 4: 4, 5: 5}
# {8: 8, 6: 6, 7: 7}
# {9: 9}
Comment

PREVIOUS NEXT
Code Example
Python :: python round up 
Python :: pip proxy settings 
Python :: most frequent element in a list 
Python :: all permutations python 
Python :: tkinter bold text 
Python :: python write list to text file 
Python :: jinja len is undefined 
Python :: how to make nmap port scanner in python 
Python :: installing more modules in pypy 
Python :: invoice parsing ocr python 
Python :: get list of users django 
Python :: panda - subset based on column value 
Python :: python convert int to bool 
Python :: python sum attribute in list 
Python :: discord.py owner only commands 
Python :: install log21 python 
Python :: django import settings variables 
Python :: print last n rows of dataframe 
Python :: python añadir elementos a una lista 
Python :: pygame left click 
Python :: f string decimal places 
Python :: rename files in folder python 
Python :: python every other goes to a list 
Python :: python global site packages 
Python :: how to get the year in python 
Python :: python datetime time in seconds 
Python :: add empty row to pandas dataframe 
Python :: python read arguments 
Python :: next day in python without using datetime 
Python :: text size legend to bottom matplotlib 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =