Is there a more elegant way to spell this?

Jean-Michel Pichavant jeanmichel at sequans.com
Tue Jan 27 08:35:33 EST 2015


----- Original Message -----
> From: "Neal Becker" <ndbecker2 at gmail.com>
> To: python-list at 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.


More information about the Python-list mailing list