Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #3247
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.095 |
| X-Spam-Evidence | '*H*': 0.81; '*S*': 0.00; 'all?': 0.09; 'pm,': 0.11; 'wrote:': 0.14; 'lookups': 0.16; 'subject:Pythonic': 0.16; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'away.': 0.23; 'skip:( 30': 0.24; 'creating': 0.26; "i'm": 0.26; 'chris': 0.27; 'message- id:@mail.gmail.com': 0.28; 'subject:?': 0.29; 'fri,': 0.29; "won't": 0.30; 'key,': 0.31; 'does': 0.31; 'paul': 0.32; 'to:addr :python-list': 0.32; 'bit': 0.33; 'right?': 0.35; 'some': 0.37; 'received:209.85': 0.37; 'apr': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'to:addr:python.org': 0.39; 'could': 0.39; 'received:209': 0.39; 'header:Received:5': 0.40; 'might': 0.40; '2011': 0.62; 'making': 0.62; 'evaluate': 0.72; 'received:209.85.210.174': 0.84; 'received:mail- iy0-f174.google.com': 0.84; 'ugly,': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=UfObovpqoaLZrewgfSPwF1qk7SK2nYuW8rWNIrDKuh4=; b=qfgfmKi1mqWsfZ1w1rpZWuS41lp7DkHGquXDnVnufX1+3kOtLe45SKXQq025ZtVAkO xuXuRXs/12aJy5X3xhKR2YQjjQpKSy1IsOBhkLga08mSdSrI9YG9jCKnUHeVH+jsw172 yr9q5RTyIEC4/Ustiaz815lMJkOuO5lceot4g= |
| DomainKey-Signature | a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=TURROB3mAHMtj/4d5k/daLNVtn7d14PJ6fprprUEl5AaeTCWoBxdWf8yfZKHVxQBrM VA5PPx0ZRmJlcvmwPAeMiJu6FKwaBMXRPQsAKeXFAMQjRkQsPcPtHJq575Kp1lwZxnGN ou/lue1hcs/R+ELTOpybN/3JN1hPzULyVKW+Y= |
| MIME-Version | 1.0 |
| In-Reply-To | <7xsjtkx9hy.fsf@ruckus.brouhaha.com> |
| References | <mailman.377.1302833455.9059.python-list@python.org> <7xsjtkx9hy.fsf@ruckus.brouhaha.com> |
| Date | Fri, 15 Apr 2011 17:35:20 +1000 |
| Subject | Re: Pythonic infinite for loop? |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| 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.383.1302852922.9059.python-list@python.org> (permalink) |
| Lines | 16 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1302852923 news.xs4all.nl 41117 [::ffff:82.94.164.166]:49281 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:3247 |
Show key headers only | View raw
On Fri, Apr 15, 2011 at 5:24 PM, Paul Rubin <no.email@nospam.invalid> wrote:
> This does 2 lookups per key, which you could avoid by making the code
> uglier (untested):
>
> sentinel = object()
> seq = (dct.get('Keyword%d'%i,sentinel) for i in count(1))
> lst = list(takewhile(lambda x: x != sentinel, seq))
If I understand this code correctly, that's creating generators,
right? It won't evaluate past the sentinel at all?
That might well be what I'm looking for. A bit ugly, but efficient and
compact. And I can bury some of the ugliness away.
Chris Angelico
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Pythonic infinite for loop? Chris Angelico <rosuav@gmail.com> - 2011-04-15 12:10 +1000
Re: Pythonic infinite for loop? Nobody <nobody@nowhere.com> - 2011-04-15 03:33 +0100
Re: Pythonic infinite for loop? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-15 02:33 +0000
Re: Pythonic infinite for loop? Chris Angelico <rosuav@gmail.com> - 2011-04-15 13:58 +1000
Re: Pythonic infinite for loop? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-15 12:52 +0000
Re: Pythonic infinite for loop? Roy Smith <roy@panix.com> - 2011-04-15 09:13 -0400
Re: Pythonic infinite for loop? Chris Angelico <rosuav@gmail.com> - 2011-04-16 01:35 +1000
Re: Pythonic infinite for loop? Paul Rubin <no.email@nospam.invalid> - 2011-04-15 09:10 -0700
Re: Pythonic infinite for loop? Paul Rubin <no.email@nospam.invalid> - 2011-04-15 00:24 -0700
Re: Pythonic infinite for loop? Chris Angelico <rosuav@gmail.com> - 2011-04-15 17:35 +1000
Re: Pythonic infinite for loop? Paul Rubin <no.email@nospam.invalid> - 2011-04-15 00:47 -0700
Re: Pythonic infinite for loop? Peter Otten <__peter__@web.de> - 2011-04-15 10:11 +0200
Re: Pythonic infinite for loop? Peter Otten <__peter__@web.de> - 2011-04-15 10:25 +0200
Re: Pythonic infinite for loop? Chris Angelico <rosuav@gmail.com> - 2011-04-15 18:32 +1000
Re: Pythonic infinite for loop? Peter Otten <__peter__@web.de> - 2011-04-15 11:32 +0200
Re: Pythonic infinite for loop? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-15 12:48 +0000
csiph-web