Integers class...?
Greg Ewing
greg at cosc.canterbury.ac.nz
Thu Mar 7 22:11:44 EST 2002
Magnus Lie Hetland wrote:
>
> from ints import ints
>
> for x in ints[0, 2, ..., 10]:
> print x
If you're doing that, it might be better to use
the existing slice notation:
for x in ints[0:11]:
...
The only new thing to learn then is that 'ints'
is a sequence containing (conceptually) all the
integers.
Hmmm, I'm sure someone suggested this before...
The only thing you don't get from that is an
easy way to iterate backwards. The best I can
think of is
for x in reverse(ints[0:11]):
But then to make it lazy, reverse() would have
to do some interesting things. (And no, I don't
want an xreverse function! I hate x... names.)
--
Greg Ewing, Computer Science Dept, University of Canterbury,
Christchurch, New Zealand
To get my email address, please visit my web page:
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list