Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32148

Re: while expression feature proposal

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'value,': 0.03; 'none)': 0.07; 'loop.': 0.09; 'subject:while': 0.09; 'value.': 0.15; 'functools': 0.16; 'n),': 0.16; 'oct': 0.16; 'returned,': 0.16; 'select,': 0.16; 'skips': 0.16; 'subject:expression': 0.16; 'wrote:': 0.17; 'thu,': 0.17; '>>>': 0.18; 'import': 0.21; 'received:mail-bk0-f46.google.com': 0.22; 'demonstrate': 0.23; 'random': 0.24; 'header:In-Reply-To:1': 0.25; 'values': 0.26; 'am,': 0.27; 'received:209.85.214.46': 0.27; 'message- id:@mail.gmail.com': 0.27; 'code': 0.31; 'not.': 0.32; 'goes': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'thomas': 0.62; 'rachel': 0.84; 'to:name:python': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=PTxX9R81ANNBmniKVgWlG5b6Up3h/bRsWVHIj8VMA6I=; b=L4g0nLKW7dfLUH8IjZV2tO9Qg6uydRTY5vmVHd+JYpBHM6dX2i2EZ9zdbnjiuH9rK0 Aq8H3Vg2WJhARLYIiRTcFFESJpYmOZ6XMcXRZRlOAVL2bgknmtoD/muLUu1gXpCEv1tF +Ep1cMp1xD4NWMUzPhDMlX2G/0lxIjsKx5CXnG5sdqkN8twKfH14kVziW32ziu1NQ4Ad Ba6eyakAIhkIBZPiKNx53PmW5IEbAIiX629uEVJESBiZqGD8yD8dlSEgS0eUzKG8R14Q 8g6linL5uJS/V7a4jui/SU7Les1BGj6J7OuC1T5NkmiN0Ak+HSZNEqktrgraSQqtE734 BfVA==
MIME-Version 1.0
In-Reply-To <CALwzid=fW-evyLpmMJk6yYrFYjU=byhTZNO6-JkOx-0k5yOrkA@mail.gmail.com>
References <CAOKWLrERVuT-u=9YZGnQUhWLv2M6F06pU20vG9W1joD9h-SdSQ@mail.gmail.com> <CALwzidm1zj5ZR4YU-DCWBgY3Q4m=UC0BNs3qJfwYpV+Kh+21cg@mail.gmail.com> <50886398.5050301@tim.thechases.com> <mailman.2803.1351119286.27098.python-list@python.org> <7x7gqf1na2.fsf@ruckus.brouhaha.com> <mailman.2807.1351121989.27098.python-list@python.org> <k6apaa$eid$1@r03.glglgl.gl> <CALwzid=fW-evyLpmMJk6yYrFYjU=byhTZNO6-JkOx-0k5yOrkA@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 25 Oct 2012 10:47:40 -0600
Subject Re: while expression feature proposal
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2857.1351183692.27098.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1351183692 news.xs4all.nl 6965 [2001:888:2000:d::a6]:37473
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32148

Show key headers only | View raw


On Thu, Oct 25, 2012 at 10:36 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Thu, Oct 25, 2012 at 1:21 AM, Thomas Rachel
> <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
> wrote:
>>> j = next(j for j in iter(partial(randrange, n), None) if j not in
>>> selected)
>>
>>
>> This generator never ends. If it meets a non-matching value, it just skips
>> it and goes on.
>
> next() only returns one value.  After it is returned, the generator is
> discarded, whether it has ended or not.  If there were no valid values
> for randrange to select, then it would descend into an infinite loop.
> But then, so would the dropwhile and the original while loop.

To demonstrate that the code does in fact return:

>>> selected = set(range(5))
>>> n = 10
>>> from functools import partial
>>> from random import randrange
>>> j = next(j for j in iter(partial(randrange, n), None) if j not in selected)
>>> j
5

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: while expression feature proposal Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-24 16:54 -0600
  Re: while expression feature proposal Paul Rubin <no.email@nospam.invalid> - 2012-10-24 16:08 -0700
    Re: while expression feature proposal Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-24 17:39 -0600
      Re: while expression feature proposal Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-10-25 09:21 +0200
        Re: while expression feature proposal Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-10-25 12:12 +0200
        Re: while expression feature proposal Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-25 10:36 -0600
          Re: while expression feature proposal Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-10-25 22:49 +0200
            Re: while expression feature proposal Dan Loewenherz <dloewenherz@gmail.com> - 2012-10-25 22:12 -0700
              Re: while expression feature proposal Paul Rubin <no.email@nospam.invalid> - 2012-10-25 23:06 -0700
                Re: while expression feature proposal Chris Angelico <rosuav@gmail.com> - 2012-10-26 17:23 +1100
                Re: while expression feature proposal Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-26 09:43 +0000
                Re: while expression feature proposal Dan Loewenherz <dloewenherz@gmail.com> - 2012-10-26 08:29 -0700
                Re: while expression feature proposal Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-26 09:42 -0600
                Re: while expression feature proposal Paul Rubin <no.email@nospam.invalid> - 2012-10-26 09:10 -0700
                Re: while expression feature proposal Cameron Simpson <cs@zip.com.au> - 2012-10-27 09:03 +1100
                Re: while expression feature proposal Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-26 16:48 -0600
                Re: while expression feature proposal Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-27 00:07 +0000
                Re: while expression feature proposal Paul Rubin <no.email@nospam.invalid> - 2012-10-26 20:43 -0700
                Re: while expression feature proposal Tim Chase <sed@thechases.com> - 2012-10-26 18:26 -0500
                Re: while expression feature proposal Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-26 19:41 -0400
                Re: while expression feature proposal Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-26 19:19 -0400
                Re: while expression feature proposal Chris Angelico <rosuav@gmail.com> - 2012-10-27 11:42 +1100
              Re: while expression feature proposal Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-26 19:12 -0400
                Re: while expression feature proposal Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-27 00:18 +0000
                Re: while expression feature proposal Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-26 20:27 -0400
                Re: while expression feature proposal Tim Chase <python.list@tim.thechases.com> - 2012-10-27 14:15 -0500
              Re: while expression feature proposal Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-26 19:51 -0400
        Re: while expression feature proposal Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-25 10:47 -0600
    Re: while expression feature proposal Paul Rudin <paul.nospam@rudin.co.uk> - 2012-10-25 10:35 +0100

csiph-web