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?

Date 2015-01-27 14:35 +0100
From Jean-Michel Pichavant <jeanmichel@sequans.com>
Subject Re: Is there a more elegant way to spell this?
Newsgroups comp.lang.python
Message-ID <mailman.18172.1422367680.18130.python-list@python.org> (permalink)

Show all headers | 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