Most viewed recipes tagged "iterators"http://code.activestate.com/recipes/tags/iterators/views/2016-07-23T22:17:29-07:00ActiveState Code RecipesPHP 'Struct' port (PHP)
2010-03-28T01:22:31-07:00Jeff Griffithshttp://code.activestate.com/recipes/users/835605/http://code.activestate.com/recipes/577160-php-struct-port/
<p style="color: grey">
PHP
recipe 577160
by <a href="/recipes/users/835605/">Jeff Griffiths</a>
(<a href="/recipes/tags/iterator/">iterator</a>, <a href="/recipes/tags/iterators/">iterators</a>, <a href="/recipes/tags/oop/">oop</a>).
Revision 2.
</p>
<p>In Ruby, the <a href="http://ruby-doc.org/core/classes/Struct.html">Struct class</a> is a convenient way to create a hash-like object on the fly and use it for your nefarious purposes. PHP 5+ can be convinced to do this type of things as well, it just doesn't have it out of the box. Here is a simple class that implements iterator and allows you to populate the internal data structure similar to how Ruby's Struct works. Syntactic sugar? Probably.</p>
<p>Note: I haven't bothered to implement the Ruby Struct API per se, Instead I just got something similar by implementing the Iterator interface and keeping things very PHP-like.</p>
Create PDF control break reports with itertools.groupby and xtopdf (Python)
2016-07-23T22:17:29-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580692-create-pdf-control-break-reports-with-itertoolsgro/
<p style="color: grey">
Python
recipe 580692
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/control/">control</a>, <a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/grouping/">grouping</a>, <a href="/recipes/tags/iterators/">iterators</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/reportgeneration/">reportgeneration</a>, <a href="/recipes/tags/reporting/">reporting</a>, <a href="/recipes/tags/sql/">sql</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to create the classic control break style of report (a staple of data processing) using Python along with the groupby function from the itertools module, and xtopdf, a Python toolkit for PDF creation.</p>
Infinite list of primes! Yay! (Python)
2010-07-20T04:05:00-07:00Alejandro Peraltahttp://code.activestate.com/recipes/users/4174433/http://code.activestate.com/recipes/577318-infinite-list-of-primes-yay/
<p style="color: grey">
Python
recipe 577318
by <a href="/recipes/users/4174433/">Alejandro Peralta</a>
(<a href="/recipes/tags/iterators/">iterators</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/primes/">primes</a>).
</p>
<p>It's an iterator that returns prime numbers. </p>
<p>Got the idea from here: <a href="http://www.cs.hmc.edu/%7Eoneill/papers/Sieve-JFP.pdf" rel="nofollow">www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf</a></p>
Interleaving file lines using iterators (Python)
2009-02-23T04:07:37-08:00David Mosshttp://code.activestate.com/recipes/users/4124829/http://code.activestate.com/recipes/576665-interleaving-file-lines-using-iterators/
<p style="color: grey">
Python
recipe 576665
by <a href="/recipes/users/4124829/">David Moss</a>
(<a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/generators/">generators</a>, <a href="/recipes/tags/iterators/">iterators</a>, <a href="/recipes/tags/manipulation/">manipulation</a>).
</p>
<p>Accepts one of more files and/or globs and interleaves the lines from each writing the result to stdout.</p>
Tail multiple pidgin IRC logfiles (Python)
2015-06-06T12:13:00-07:00Anton Vredegoorhttp://code.activestate.com/recipes/users/2667360/http://code.activestate.com/recipes/579066-tail-multiple-pidgin-irc-logfiles/
<p style="color: grey">
Python
recipe 579066
by <a href="/recipes/users/2667360/">Anton Vredegoor</a>
(<a href="/recipes/tags/colorize/">colorize</a>, <a href="/recipes/tags/irc/">irc</a>, <a href="/recipes/tags/iterators/">iterators</a>, <a href="/recipes/tags/logfiles/">logfiles</a>, <a href="/recipes/tags/merging/">merging</a>, <a href="/recipes/tags/nonblocking/">nonblocking</a>, <a href="/recipes/tags/pidgin/">pidgin</a>, <a href="/recipes/tags/tail/">tail</a>, <a href="/recipes/tags/threads/">threads</a>).
Revision 2.
</p>
<p>Tail multiple pidgin IRC logfiles. </p>
<p>Pidgin should be connected to IRC with the channels one
wants to tail joined, and it should save logs as text.</p>
<p>The script needs two arguments:</p>
<pre class="prettyprint"><code>the directory containing the directories with channel logs
a list of channel names, quoted and separated by spaces
</code></pre>
<p>Example command:</p>
<p>python pidgin-irctail.py
-d <a href="mailto:~/.purple/logs/irc/YOUR_IRC_HANDLE@irc.freenode.net">~/.purple/logs/irc/YOUR_IRC_HANDLE@irc.freenode.net</a>
-c "#chan1 #chan2 #chan3"</p>
<p>Some text elements are higlighted, and channel names are
inserted into the log lines after the time info.</p>
<p>If more than one channel is entered, the output of the logs
is merged. </p>
Fast flatten() with depth control and oversight over which subtrees to expand (Python)
2010-11-26T11:10:01-08:00Kevin L. Sitzehttp://code.activestate.com/recipes/users/4173535/http://code.activestate.com/recipes/577470-fast-flatten-with-depth-control-and-oversight-over/
<p style="color: grey">
Python
recipe 577470
by <a href="/recipes/users/4173535/">Kevin L. Sitze</a>
(<a href="/recipes/tags/flatten/">flatten</a>, <a href="/recipes/tags/iterator/">iterator</a>, <a href="/recipes/tags/iterators/">iterators</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/optimal_solution/">optimal_solution</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sequence/">sequence</a>, <a href="/recipes/tags/tuple/">tuple</a>).
</p>
<p>Extremely fast, non-recursive, depth limited flatten with powerful control over which subtrees are to be expanded. If this is what you need then look no further.</p>