All Questions

1377
votes
55answers
532017 views

How do you split a list into evenly sized chunks?

I have a list of arbitrary length, and I need to split it up into equal size chunks and operate on it. There are some obvious ways to do this, like keeping a counter and two lists, and when the second...
319
votes
32answers
74043 views

What is the most "pythonic" way to iterate over a list in chunks?

I have a Python script which takes as input a list of integers, which I need to work with four integers at a time. Unfortunately, I don't have control of the input, or I'd have it passed in as a list...
71
votes
18answers
57380 views

Splitting a list into N parts of approximately equal length

What is the best way to divide a list into roughly equal parts? For example, if the list has 7 elements and is split it into 2 parts, we want to get 3 elements in one part, and the other should have 4...
4
votes
1answers
2542 views

R:Loops to process large dataset(GBs) in chunks?

I have a large data set in GBs that I'd have to process before I analyse them. I tried creating a connector, which allows me to loop through the large datasets and extract chunks at a time.This allows...
2
votes
2answers
1988 views

Splitting a string into chunks by numeric or alpha char with Javascript

So I have this: var str = A123B234C456; I need to split it into comma separated chunks to return something like this: A,123,B,234,c,456 I thought regex would be best for this but i keep getting stu...
14
votes
2answers
13590 views

How do you split a csv file into evenly sized chunks in Python?

In a basic I had the next process. import csv reader = csv.reader(open('huge_file.csv', 'rb')) for line in reader: process_line(line) See this related question. I want to send the process line...
13
votes
2answers
2395 views

How to change knitr options mid chunk

Hi I would like to change chunk options, mid chunk, without having to create a new chunk.. running the following code I would expect to get two very different size outputs, but for some reason this d...
8
votes
2answers
6127 views

How is the skipping implemented in Spring Batch?

I was wondering how I could determine in my ItemWriter, whether Spring Batch was currently in chunk-processing-mode or in the fallback single-item-processing-mode. In the first place I didn't find the...
2
votes
2answers
430 views

Appending a png pHYs chunk in php

I'm trying to tack on some information about the physical size for printing my PNGs just before they are generated. Reading the libpng doc and the pHYs chunk specifications has been helpful but I jus...
8
votes
1answers
5321 views

Paging python lists in slices of 4 items

Possible Duplicate: How do you split a list into evenly sized chunks in Python? mylist = [1, 2, 3, 4, 5, 6, 7, 8, 9] I need to pass blocks of these to a third party API that can only deal...

Previous Next