Is there a more elegant way to spell this?

random832 at random832 at
Tue Jan 27 19:13:39 CET 2015

On Tue, Jan 27, 2015, at 13:05, Mario Figueiredo wrote:
> In article <qot7fw8s3la.fsf at>, 
> jpiitula at 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