bor.borygmus

A programming weblog by Hao Lian. • A long walk through an angry forest. • A series of memory leaks brought on by senility.

The setup.

>>> a = range(1, 6)
>>> a
[1, 2, 3, 4, 5]

The take.

>>> zip(a, a, a)
[(0, 0, 0), (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5)]

The con.

>>> i = iter(a)
>>> zip(i, i, i)
[(0, 1, 2), (3, 4, 5)]

The explanation.

David Jones makes group soup out of these lemons. Since zip and iter are both implemented in C, this is one of the fastest and tersest ways to group.

[(January 30, 2009) .]

Abandon your ideas.

Use Markdown+, but not HTML. In code blocks, beware angle brackets.