Is there a more elegant way to spell this?

random832 at fastmail.us random832 at fastmail.us
Tue Jan 27 13:13:39 EST 2015


On Tue, Jan 27, 2015, at 13:05, Mario Figueiredo wrote:
> In article <qot7fw8s3la.fsf at ruuvi.it.helsinki.fi>, 
> jpiitula at ling.helsinki.fi says...
> > 
> > If you mean literally some_predicate, then perhaps this.
> > 
> > if some_predicate:
> >    for x in seq:
> >       handle(x)
> > 
> 
> Careful. See Chris Warrick answer for the correct position of the 'if' 
> statement.

I think by "if you mean literally some_predicate" he was taking
some_predicate as a variable [rather than an expression] that does not
change during the loop. That'd be a silly thing to do in the originally
posted code, though, since it'd be easier to do "[] if not
some_predicate else [...]"



More information about the Python-list mailing list