Most viewed recipes tagged "iterable" and "generator" but not "context_manager"http://code.activestate.com/recipes/tags/iterable+generator-context_manager/views/2014-09-20T19:20:46-07:00ActiveState Code RecipesCycling a sequence (Python)
2014-09-20T19:20:46-07:00Tomas Nordinhttp://code.activestate.com/recipes/users/4189558/http://code.activestate.com/recipes/578942-cycling-a-sequence/
<p style="color: grey">
Python
recipe 578942
by <a href="/recipes/users/4189558/">Tomas Nordin</a>
(<a href="/recipes/tags/cyclic_iterator/">cyclic_iterator</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/iterable/">iterable</a>, <a href="/recipes/tags/iterator/">iterator</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>A post-it function to cycle through some sequence. Better use itertools.cycle if for any iterable.</p>
Windowing an iterable with itertools (Python)
2010-04-15T18:45:41-07:00Daniel Cohnhttp://code.activestate.com/recipes/users/4172918/http://code.activestate.com/recipes/577196-windowing-an-iterable-with-itertools/
<p style="color: grey">
Python
recipe 577196
by <a href="/recipes/users/4172918/">Daniel Cohn</a>
(<a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/iterable/">iterable</a>, <a href="/recipes/tags/iterator/">iterator</a>, <a href="/recipes/tags/loop/">loop</a>, <a href="/recipes/tags/peeking/">peeking</a>, <a href="/recipes/tags/window/">window</a>).
</p>
<p>Oftentimes a programmer needs to peek into an iterator without advancing it, a task for which many good solutions already exist. But what if the intrepid coder needs a fast and pythonic way to 'window' the data? This recipe demonstrates how to wrap any iterable with a class that adds two methods, prev and peek.</p>