PEP 276 Simple Iterator for ints

David Eppstein eppstein at ics.uci.edu
Tue Nov 13 20:05:00 EST 2001


In article <mailman.1005697518.27196.python-list at python.org>,
 James_Althoff at i2.com wrote:

> Thanks for your interesting example.  I agree that your notation "[n-1,
> n-2, ... 0]" is a very nice way of showing a sequence of integers.  I'm not
> sure how one would turn this into programming language syntax that would be
> as clear.  I think your notation works really well for your pseudo-code.
> Nice!
> 
> Not so much to defend PEP 276 but more for fun :-),
> 
> ...since your example is mathematics-oriented ("Dynamic Programming and
> Optimal Triangulation") and is meant to be a descriptive notation of an
> algorithm for your (presumably) *math-oriented* students, it might be
> interesting/amusing to note that PEP 276 would allow the following:
> 
> for i in [n-1-a for a in n]:
>     for j in [i+1+a for a in n-i]:
>         # do something

Actually, the class in question is aimed at the non-theory students.
But even for theory students, I think it would be helpful to avoid 
unnecessary confusion -- I'd rather they spent more time understanding the 
big picture of how the algorithms work, and less time decoding loop indices.
-- 
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