P
P
pcdesign2018-08-08 10:04:52
Python
pcdesign, 2018-08-08 10:04:52

How to split an array into files of a fixed size?

import random
arr = random.sample(range(1, 1000000), 1000)

There is an array arr. How to split it into files no more than 3kb?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-08-08
@pcdesign

def chunkify(items, chunk_size):
    for i in range(0, len(items), chunk_size):
        yield items[i:i+chunk_size]


chunks = chunkify(arr, 128)

Each chunks element will be no larger than 3kb.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question