PEP 284, Integer for-loops

David Eppstein eppstein at ics.uci.edu
Wed Mar 6 17:23:02 EST 2002


In article <slrna8d4bj.utc.grey at teleute.dmiyu.org>,
 Steve Lamb <grey at despair.dmiyu.org> wrote:

>  Perceived lack.  IE, this is a solution looking for a problem.  I read it
> and really have to ask.... why?  If people have a problem with it they just
> need to flip open their Python book and take a few seconds to look it up.

The situation where I came across this perceived lack was attempting to 
use Python syntax to explain the algorithms in an algorithms class 
(useful exercise btw, I think the students gained from being able to see 
code that actually worked instead of pseudocode, and Python allows many 
algorithms to be expressed clearly without distracting the students with 
lots of unnecessary pointer-banging).

Some algorithms (especially in dynamic programming) are expressed most 
naturally in terms of integer loops, the ranges of the loops are often 
closed rather than open or sometimes need to go in backwards rather than 
forward order.  Python's range() syntax makes this awkward and detracts 
from the reason I wanted to use Python: a simple syntax that expresses 
algorithms cleanly and understandably, that does not force students to 
buy Python books (this is very much not a programming class) or look up 
unfamiliar syntax, and that also is able to run those algorithms 
directly.

I realize that's a different purpose than most working Python 
programmers, but anything that leads to greater readability and easy of 
understanding should be helpful in that world too.



More information about the Python-list mailing list