On 12/8/11 7:16 AM, Eric Kangas wrote:
Hi,

I remembering reading one of the pdf's for sage when I found this
peice of code that turns a number into a list of individual numbers. I
can't seem to find this code again. An example of this code would be
taking Pi out to 100 sig figs, and get an output of each individual
sig fig in a list.


Like this?

sage: a=list(str(n(pi,100)))
sage: a
['3', '.', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5', '8', '9', '7', '9', '3', '2', '3', '8', '4', '6', '2', '6', '4', '3', '3', '8', '3', '3']
sage: a.remove('.')
sage: a
['3', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5', '8', '9', '7', '9', '3', '2', '3', '8', '4', '6', '2', '6', '4', '3', '3', '8', '3', '3']
sage: [int(x) for x in a]
[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 3]

On the other hand, if you have an integer, you can use the digits() method:

sage: 100100299499523949.digits()
[9, 4, 9, 3, 2, 5, 9, 9, 4, 9, 9, 2, 0, 0, 1, 0, 0, 1]
sage: list(reversed(100100299499523949.digits()))
[1, 0, 0, 1, 0, 0, 2, 9, 9, 4, 9, 9, 5, 2, 3, 9, 4, 9]

Thanks,

Jason

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