[Edu-sig] Are you series() on teaching with range()?
Fotis Georgatos
gef@ceid.upatras.gr
Sun, 29 Sep 2002 00:52:23 +0300
So,
I just finished a presentation today in an educational conference here in Rhodes
(Greece) regarding a research work done with Python during last year.
(look for more on that at http://amstel.science.uva.nl/~fotisg/python/)
In the meantime, I have optimized my wrapper function for the xrange() keyword,
and its range() equivalent, which both seem to constantly confuse a few novices:
>>> def xseries(first,last,step=1):
if last>=first and step>=0:
return xrange(first,last+1,step)
elif last<first and step<0:
return xrange(first,last-1,step)
return []
>>> def series(first,last,step=1):
return [x for x in xseries(first,last,step)]
>>> series(100,-8,-3)
[100, 97, 94, 91, 88, 85, 82, 79, 76, 73, 70, 67, 64, 61, 58, 55, 52, 49, 46, 43, 40, 37, 34, 31, 28, 25, 22, 19, 16, 13, 10, 7, 4, 1, -2, -5, -8]
Compare with...
>>> range(100,-8,-3)
[100, 97, 94, 91, 88, 85, 82, 79, 76, 73, 70, 67, 64, 61, 58, 55, 52, 49, 46, 43, 40, 37, 34, 31, 28, 25, 22, 19, 16, 13, 10, 7, 4, 1, -2, -5]
Am I the only one reporting this case with range()?
PS.
A random gift...
http://amstel.science.uva.nl/~fotisg/python/documents/computer_languages_evolution.png
And if you decide to read the .pdf on the same site, prefer to print it
in order to read easily the anecdotal footnotes...
cheers,
Fotis