Status of PEP's?
greg at cosc.canterbury.ac.nz
Fri Mar 1 05:28:31 CET 2002
James_Althoff at i2.com wrote:
> def doSomethingFromTo(start,end):
> The function has to test to see which of "start" and "end" is the smaller
> value in order to know whether to execute a for-loop with "<" or a for-loop
> with ">" (and the code specified in each separate for-loop has to be
> written redundantly).
This is no worse than what you would have to do to
achieve the same thing using range() or any other
If I were writing a function like that, I think I'd
make the caller responsible for passing the arguments
in the right order. But if you really want, you can
always sort out the argument order before entering
the loop, e.g.
if start > end:
start, end = end, start
for start <= i < end:
No redundant for-loop code required.
Greg Ewing, Computer Science Dept, University of Canterbury,
Christchurch, New Zealand
To get my email address, please visit my web page:
More information about the Python-list