IntSpan?
Chris Liechti
cliechti at gmx.net
Thu Mar 21 14:30:01 EST 2002
"Jeff Bienstadt" <jeffbi at jetsoft.com> wrote in
news:3c9a1ae9$1 at news.nwlink.com:
> "Neal Norwitz" <neal at metaslash.com> wrote in message
> news:3C99F049.5A78B149 at metaslash.com...
>> Jeff Bienstadt wrote:
>> > I'm looking for something that inteligently handles and
manipulates
>> > spans of integers, such as: 2-356,456,458-500
>>
>> I'm not familiar with IntSpan, but have you looked at the builtin
>> range()?
>> >>> print range.__doc__
>> range([start,] stop[, step]) -> list of integers
>>
> Yes, I knew about range, but that's not quite what I'm looking for.
>
> Using range to create the full list of integers seems prohibitively
> expensive --- spans in the range 1-400000 are not at all out of
> line.
>
...
> I can see from your reply how range could be useful in the
> implementation, for creating temporary lists of values to work
> with but again, since the spans could be quite long, this
> seems expensive.
in ypthon 2.2 you could do that with a generator.
>>> form __future__ import generators
>>> def spanning():
... for i in xrange(3,10):
... yield i
... yield 99
... for i in xrange(20,30):
... yield i
testing:
>>> for i in spanning(): print i
using xrange instead of range does not allocate a list but generates
the vaulues when they're needed.
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list