PEP 276 Simple Iterator for ints (fwd)

David Eppstein eppstein at ics.uci.edu
Wed Dec 5 14:01:09 EST 2001


I redid my lecture notes <http://www.ics.uci.edu/~eppstein/260/011023/> 
using Greg Ewing's "for lb <= var < ub" syntax in place of my previous
"for var in [lb, lb+1, ... ub]".

I'm happy with the result -- it's both more concise and (I think) more 
readable.  I found to my surprise that, even though my previous syntax used 
closed intervals, what I really wanted were either half-open intervals (but 
half-open on the opposite side to that produced by range) or in one case a 
fully open interval.  Greg's syntax handles this nicely.  Note also that in 
one case I am using the "for" within a list comprehension, and the lack of 
nested brackets there is a further boost to readability.

I'd be even happier if this could be made to work in actual Python instead 
of just Python-like pseudo-code.
-- 
David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/



More information about the Python-list mailing list