Latest recipes tagged "iterators" Code RecipesCreate PDF control break reports with itertools.groupby and xtopdf (Python) 2016-07-23T22:17:29-07:00Vasudev Ram <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> Tail multiple pidgin IRC logfiles (Python) 2015-06-06T12:13:00-07:00Anton Vredegoor <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 -d <a href="mailto:~/.purple/logs/irc/">~/.purple/logs/irc/</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. Sitze <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> Infinite list of primes! Yay! (Python) 2010-07-20T04:05:00-07:00Alejandro Peralta <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="" rel="nofollow"></a></p> PHP 'Struct' port (PHP) 2010-03-28T01:22:31-07:00Jeff Griffiths <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="">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> Interleaving file lines using iterators (Python) 2009-02-23T04:07:37-08:00David Moss <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>