Popular recipes tagged "iterable" but not "iterator"http://code.activestate.com/recipes/tags/iterable-iterator/2014-10-02T12:13:52-07:00ActiveState Code RecipesNumbers as Ranges - iterable integers (C++) 2014-10-02T12:13:52-07:00elazarhttp://code.activestate.com/recipes/users/4187847/http://code.activestate.com/recipes/578945-numbers-as-ranges-iterable-integers/ <p style="color: grey"> C++ recipe 578945 by <a href="/recipes/users/4187847/">elazar</a> (<a href="/recipes/tags/iterable/">iterable</a>, <a href="/recipes/tags/range/">range</a>). Revision 2. </p> <p>This header file makes simple integers iterable. Note that it works only on C++11 or above.</p> <p>Usage:</p> <pre class="prettyprint"><code>#include "num_range.h" for (int i : 3) cout &lt;&lt; i &lt;&lt; endl; </code></pre> <p>Output: 0 1 2</p> <p>Implementation note: This code is far too generic. We only need <code>DerefableInt</code>. The templates are there for no practical reason.</p> <p>Cons: pollutes namespace std; nonstandard idiom;</p> Truth Value Aware Iterable (Python) 2013-06-11T08:00:25-07:00Alan Franzonihttp://code.activestate.com/recipes/users/4169882/http://code.activestate.com/recipes/578549-truth-value-aware-iterable/ <p style="color: grey"> Python recipe 578549 by <a href="/recipes/users/4169882/">Alan Franzoni</a> (<a href="/recipes/tags/boolean/">boolean</a>, <a href="/recipes/tags/iterable/">iterable</a>, <a href="/recipes/tags/truth/">truth</a>). </p> <p>This small recipe enables truth value testing on iterables.</p> <p>It is quite common to do things like:</p> <pre class="prettyprint"><code>if somesequence: ... else: ... </code></pre> <p>Such constructs, that enter the if block if the sequence's got one or more elements and the else block if it's empty, work fine on non-lazy builtin sequences (lists, strings, tuples) and dictionaries as well, but doesn't necessarily work on generic iterables - most of them are always true regardless of their contents, since they're some kind of object. A classical example is generators, but such behaviour can be extended to any object implementing the Iterable interface.</p> <p>Just wrap your iterable with this decorator and you'll get a truth-aware iterable which supports proper truth testing by doing a small first element prefetching and can then be used just like the original iterable.</p> Iterator Offsetter (Python) 2012-04-16T13:08:55-07:00Josh Bodehttp://code.activestate.com/recipes/users/4179046/http://code.activestate.com/recipes/577852-iterator-offsetter/ <p style="color: grey"> Python recipe 577852 by <a href="/recipes/users/4179046/">Josh Bode</a> (<a href="/recipes/tags/iterable/">iterable</a>, <a href="/recipes/tags/itertools/">itertools</a>, <a href="/recipes/tags/offset/">offset</a>). Revision 2. </p> <p>Produces a list of copies of an iterable that are offset by the supplied offsets.</p>