Note that there are some explanatory texts on larger screens.

plurals
  1. USabarnert
    primarykey
    data
    text
    <p>Some people, when confronted with a problem, think "I know, I'll use <a href="http://docs.python.org/3/library/itertools.html" rel="nofollow noreferrer">itertools</a>."</p> <p>Now they have <code>next(takewhile(not_, count()))</code> problems.</p> <hr> <p>Since I've been asked about this multiple times now:</p> <p>It's a reference to <a href="http://www.codinghorror.com/blog/2008/06/regular-expressions-now-you-have-two-problems.html" rel="nofollow noreferrer">"Now they have two problems"</a> about regular expressions. <code>next(takewhile(not_, count()))</code> is guaranteed to give you <code>0</code>, and pretty efficiently… but it's not exactly readable. Which is the joke. <code>itertools</code> <em>does</em> solve all your problems, but you don't <em>always</em> need to use it.</p> <p>If you don't grasp the paradigm, go read <a href="http://www.dabeaz.com/generators-uk/" rel="nofollow noreferrer">David Beazley's presentations</a>. Once you do: "I've got a CSV, and I want to group the rows by…" Pass a <code>csv.reader</code> to <code>groupby</code>. "I've got a bunch of values, and I want to take them 4 at a time and…" Use <code>grouper</code> from the recipes. "I've got a file, and I want to take each pair of adjacent lines and…" <code>tee</code> it, <code>next</code> one copy, and <code>zip</code> them. And so on.</p> <p>But of course some problems have an even <em>easier</em> solution, and once you start thinking in terms of sequences of transformations on iterators, sometimes you'll miss the easier answer.</p> <p>(The exact same thing happens with <code>numpy</code>, of course.)</p>
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload