[Python-ideas] Assignments in list/generator expressions
Nick Coghlan
ncoghlan at gmail.com
Tue Apr 12 01:49:12 CEST 2011
More information about the Python-ideas mailing list
Tue Apr 12 01:49:12 CEST 2011
- Previous message: [Python-ideas] Assignments in list/generator expressions
- Next message: [Python-ideas] Assignments in list/generator expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Apr 12, 2011 at 9:17 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote: > Nick Coghlan wrote: > >> ys = [y for x in xs given f(x) as y if y] > > Hmmm. Here I find myself getting tripped up by the ordering > when I try to read that smoothly. > > I think it's because words like 'given' or 'where', as used > in mathematics, imply a definition of something that's been > used *before*, whereas here it's defining something to be > used *after* (i.e. in the following 'if' clause). This one is tricky, since the assignment is *after* the for loop, but *before* the filter condition. You could reorder it as below, but the translation to long-form Python code wouldn't be quite as clean (since the order of clauses wouldn't follow the order of nesting any more). ys = [y for x in xs if y given f(x) as y] Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-ideas] Assignments in list/generator expressions
- Next message: [Python-ideas] Assignments in list/generator expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list