On Sun, Jul 31, 2011 at 10:54 AM, Justin C. Walker <jus...@mac.com> wrote:
>
> On Jul 31, 2011, at 02:29 , tvn wrote:
>
>> The enumerate function in Python has the index type as 'int'  instead of say
>> sage's Integer.   is there an equivalent of enumerate in Sage that returns
>> Integer type ?  Thanks
>
> Try srange and sxrange/xsrange.

Those do something different -- they give a range of values.  In
contrast, enumerate takes an iterable x, and returns an iterator over
tuples (i,x[i]) with i a Python int.    I think the OP is asking
whether there is something like "senumerate(x)" that would return an
iterator over pairs (i,x[i]), with i Sage integers.  I think there is
no such single function.   Since it is easy to write such a thing in
2-3 lines of code (see below -- or just throw in a coercion), the only
reason they could be asking is they want maximal speed...?  But that
isn't explained in the question.  Hmmm.  Not sure what to do.

# Here is the 2-liner:

def senumerate(x):
    for i, a in enumerate(x): yield Integer(i),a



sage: v = list(senumerate(['a','b','c'])); v
[(0, 'a'), (1, 'b'), (2, 'c')]
sage: type(v[0][0])
<type 'sage.rings.integer.Integer'>
sage: list(enumerate(['a','b','c']))
[(0, 'a'), (1, 'b'), (2, 'c')]




>
> Details with "?"
>
> HTH
>
> Justin
>
> --
> Justin C. Walker
> Curmudgeon at Large
> Director
> Institute for the Enhancement of the Director's Income
> --
> Build a man a fire and he'll be warm
>  for a night.
> Set a man on fire and he'll be warm
>  for the rest of his life.
>
>
>
> --
> To post to this group, send email to sage-support@googlegroups.com
> To unsubscribe from this group, send email to 
> sage-support+unsubscr...@googlegroups.com
> For more options, visit this group at 
> http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org
>



-- 
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to