What is pythons equivalent of Ruby’s each_slice(count)?
I want to take 2 elements from list for each iteration.
Like for [1,2,3,4,5,6] I want to handle 1,2 in first iteration then 3,4 then 5,6.
Ofcourse there is a roundabout way using index values. But is there a direct function or someway to do this directly?
What is pythons equivalent of Ruby’s each_slice(count) ? I want to take 2 elements
Share
There is a recipe for this in the itertools documentation called grouper:
Use like this: