enumerable

Python Equivalent to Ruby's #each_cons?

Python Equivalent to Ruby's #each_cons? Question: Is there a Pythonic equivalent to Ruby’s #each_cons? In Ruby you can do this: array = [1,2,3,4] array.each_cons(2).to_a => [[1,2],[2,3],[3,4]] Asked By: maxhawkins || Source Answers: For such things, itertools is the module you should be looking at: from itertools import tee, izip def pairwise(iterable): “s -> (s0,s1), (s1,s2), …

Total answers: 9