Dan Loewenherz <dloewenh...@gmail.com> writes:
> VAR = EXPR
> while VAR:
>     BLOCK
>     VAR = EXPR

for VAR in iter(lambda: EXPR, None):
   BLOCK

where the termination sentinel might be False or '' or whatever instead
of None.  Of course if EXPR is a callable, there's no lambda.

> while EXPR as VAR:
>     BLOCK

This is kind of nice.  I wonder if it could generalize "with" somehow,
i.e. use the context manager for EXPR if it has one.  Or maybe "iter"
could be generalized so you could pass an arbutrary predicate as
termination condition, instead of a single sentinel value.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to