On Thu, Jun 5, 2014 at 5:43 PM, Makoto Yamashita <[email protected]> wrote:

> Hi,
>
> I noticed that fractions in nested list comprehensions are apparently
> interpreted in the Python way. So, with the input
> [[j/k for j in range(1,k+1)] for k in range(1,5)]
> I get
> [[1], [0, 1], [0, 0, 1], [0, 0, 0, 1]] .
> With a single level there's no such issue: [j/3 for j in range(1,4)]
> returns [1/3, 2/3, 1] .
> For now I'm dealing with it by enclosing the variables in Integer(). Is
> there any better solution?
>

This is pretty much *the* worst gotcha of Sage.   You could do this instead:

[[j/k for j in srange(1,k+1)] for k in srange(1,5)]

It makes a range-like object, but respects the types of the input variables
of the srange, which are Integer in this case.

 -- William



>
> thanks,
> Makoto
>
>  --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.
>



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

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to