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


Groups > comp.lang.python > #84644

Re: Is there a more elegant way to spell this?

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=46224e9c9=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status UNSURE 0.426
X-Spam-Level ****
X-Spam-Evidence '*H*': 0.23; '*S*': 0.08; 'elegant': 0.07; 'prevents': 0.09; 'python': 0.11; 'creating': 0.23; 'this?': 0.23; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; '-----': 0.33; 'could': 0.34; 'but': 0.35; 'there': 0.35; 'subject:?': 0.36; 'similar': 0.36; 'email addr:python.org': 0.37; 'list.': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'expression': 0.60; 'new': 0.61; 'you.': 0.62; 'information': 0.63; 'received:194': 0.64; 'subject:more': 0.64; 'more': 0.64; 'email name:python-list': 0.65; 'to:addr:gmail.com': 0.65; 'notice:': 0.67; 'person,': 0.68; 'subject:there': 0.68; 'privileged.': 0.69; 'disclose': 0.74; 'subject:this': 0.83; '2015': 0.84; 'medium.': 0.91
X-IronPort-AV E=Sophos;i="5.09,474,1418079600"; d="scan'208";a="3889459"
Date Tue, 27 Jan 2015 14:35:33 +0100 (CET)
From Jean-Michel Pichavant <jeanmichel@sequans.com>
To Neal Becker <ndbecker2@gmail.com>, python-list@python.org
In-Reply-To <ma8311$q4c$1@ger.gmane.org>
Subject Re: Is there a more elegant way to spell this?
MIME-Version 1.0
X-Mailer Zimbra 7.2.7_GA_2942 (ZimbraWebClient - GC37 (Linux)/7.2.7_GA_2942)
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding base64
X-Mailman-Approved-At Tue, 27 Jan 2015 15:07:58 +0100
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.18172.1422367680.18130.python-list@python.org> (permalink)
Lines 15
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1422367680 news.xs4all.nl 2843 [2001:888:2000:d::a6]:47290
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:84644

Show key headers only | View raw


----- Original Message -----
> From: "Neal Becker" <ndbecker2@gmail.com>
> To: python-list@python.org
> Sent: Tuesday, 27 January, 2015 2:15:12 PM
> Subject: Is there a more elegant way to spell this?
> 
> Is there a more elegant way to spell this?
> 
> for x in [_ for _ in seq if some_predicate]:

You could use a generator expression

for x in (_ for _ in seq if some_predicate):

This is very similar but it prevents python from creating a new list.


JM



-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

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


Thread

Re: Is there a more elegant way to spell this? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2015-01-27 14:35 +0100

csiph-web