William,

I'm sorry to see that irange is not in sage-2.8.5.

Your comment:

> I think http://trac.sagemath.org/sage_trac/ticket/702 is actually much nicer 
> to use, so for now I think irange isn't needed.

is not quite to the point.

irange can take three arguments: start, stop and step.
The arguments are not restricted to integers.

See the examples I give. Moreover I think irange is more Pythonic!

As irange is based only on srange it will be fast now tick #701 is closed.

Arguments enough to reopen ticket #706, I think.

Jaap

> sage: v = irange(0,5); v
> [0, 1, 2, 3, 4, 5]
> sage: v = irange(1,10); v
> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> sage: v = irange(10,-1,-1); v
> [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1]

> sage: v = irange(1,8, 1/2); v
> [1, 3/2, 2, 5/2, 3, 7/2, 4, 9/2, 5, 11/2, 6, 13/2, 7, 15/2, 8]
> sage: v = irange(1,2, 0.4); v
> [1, 1.40000000000000, 1.80000000000000]
> sage: v = irange(1, 2, 0.5); v
> [1, 1.50000000000000, 2]
> sage: v = irange(1, 2, -0.5); v
> []
> sage: v = irange(2, -2, -0.5); v
> [2, 1.50000000000000, 1.00000000000000, 0.500000000000000, 0.000000000000000, 
> -0.500000000000000, -1.00000000000000, -1.50000000000000, -2]
> sage: v = irange(10,1); v
> []
> sage: v = irange(10,10); v
> [10]
> sage: v = irange(10); v
> Traceback (most recent call last):
> ...
> TypeError: irange() takes at least 2 arguments (1 given)
> sage: v = irange(0.5, 2.5, 0.5); v
> [0.500000000000000, 1.00000000000000, 1.50000000000000, 2.00000000000000, 
> 2.50000000000000]
> sage: [n^2 for n in irange(-1, 10)]
> [1, 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
> 
> And this one from the calculus thread!
>> --  I think that the Python convention of not including the upper bound
>>> > in a sum is a real problem.
>>> >
>>> > sage: sum(i for i in range(1,10))
>>> > 45
>>> >
>>> > I understand this is a fundamental convention in Python, and that it is
>>> > very
>>> > natural for people used to malloc(), but I worry that this will be a
>>> > constant
>>> > headache for students (and professors!).
> 
> 
> sage: sum(i for i in irange(1, 10))
> 55 




--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to