A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2009-January/085181.html below:

Add a "while" clause to generator expressions

[Python-Dev] PEP 3142: Add a "while" clause to generator expressionsGerald Britton gerald.britton at gmail.com
Mon Jan 19 17:59:35 CET 2009
The sieve is just one example.  The basic idea is that for some
infinite generator (even a very simple one) you want to cut it off
after some point.  As for the number of characters, I spelled lambda
incorrectly (left out a b) and there should be a space after the colon
to conform to design guides.  So, actually the takewhile version is
two characters longer, not counting "import itertools" of course!

On Mon, Jan 19, 2009 at 11:44 AM, Daniel Stutzbach
<daniel at stutzbachenterprises.com> wrote:
> On Mon, Jan 19, 2009 at 10:37 AM, Gerald Britton <gerald.britton at gmail.com>
> wrote:
>>
>>    prime = (p for p in sieve() while p < 1000)
>>    prime = takewhile(lamda p:p<1000, sieve())
>
> I'm pretty sure the extra cost of evaluating the lambda at each step is tiny
> compared to the cost of the sieve, so I don't you can make a convincing
> argument on performance.
>
> Also, you know the latter is actually fewer characters, right? :-)
>
> --
> Daniel Stutzbach, Ph.D.
> President, Stutzbach Enterprises, LLC
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4