iterating "by twos"
kj
socyl at 987jk.com.invalid
Tue Jul 29 17:37:43 EDT 2008
In <mailman.869.1217363952.922.python-list at python.org> Terry Reedy <tjreedy at udel.edu> writes:
>kj wrote:
>> Is there a special pythonic idiom for iterating over a list (or
>> tuple) two elements at a time?
>>
>> I mean, other than
>>
>> for i in range(0, len(a), 2):
>> frobnicate(a[i], a[i+1])
>There have been requests to add a grouper function to itertools, but its
>author has resisted because there are at least three things one might do
>with the short remainder group left over when the group size does not
>evenly divide the sequence size: drop it, return it, or fill it to the
>requested groupsize with a dummy value and then return it.
Why not make this choice a third argument to the grouper function?
Kynn
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
More information about the Python-list
mailing list