On Monday, May 21, 2012 9:49:08 AM UTC-7, Eric Kangas wrote:
>
> When dealing with base 36 I realized there is no letter available to use 
> in for loops.
>
> Here is the code that I have right now.
>
> a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,t,u,v,w,x,y,z = 
> var('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,t,u,v,w,x,y,z')
>
> pie = pi.n(1000) 
>
> pie36 = list(pie.str(base=36))
>
> pie36.remove('.')
>
> a = 10; b = 11; c = 12; d = 13; e = 14; f = 15; g = 16; h = 17; i = 18; j 
> = 19; k = 20; l = 21; m = 22; n = 23; o = 24; p = 25; q = 26; r = 27; s = 
> 28; t = 29; u = 30; v = 31; w = 32; x = 33; y = 34; z = 35;
>
> pie36 = [int(ii) for ii in pie36]
>
>
> I tried using ii for the increment count for the for loop, but here is 
> what I get as the error.
>
> ---------------------------------------------------------------------------
> ValueError Traceback (most recent call last)
>
> /home/nooniensoong97/<ipython console> in <module>()
>
> ValueError: invalid literal for int() with base 10: 'i'
>
>  
>
>
> I guess you can not use more then a letter to count the increments in the 
> loop? Is there anyway to get around this issue?
>

How about:

    sage: D = dict([(Integer(j).str(base=36),j) for j in range(36)])

(This creates a dictionary with entries like '3':3 and 'a':10, associating 
a base 36 representation as a string to the corresponding integer.) Then

    sage: pie = pi.n(1000)

    sage: pie36 = list(pie.str(base=36))

    sage: pie36.remove('.')
    sage: [D[ii] for ii in pie36]

ought to do what you want.

-- 
John

-- 
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