Ask Your Question
1

x.digits() for x decimal

asked 2016-08-18 07:56:52 -0500

logomath gravatar image

Let sage: x=1416 sage: v=x.digits() sage: v.reverse(); v gives [1, 4, 1, 6] That doesn't work for x decimal, as x=3.1416 I would like to have [3, 1, 4, 1, 6] as result in a simple way.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-08-18 08:21:57 -0500

tmonteil gravatar image

There is no such method, but you can do the following:

sage: [i for i in x.str(skip_zeroes=True) if i.isdigit()]
['3', '1', '4', '1', '6']
edit flag offensive delete link more

Comments

Ok, how to reduce it to [3, 1, 4, 1, 6] ?

logomath gravatar imagelogomath ( 2016-08-18 08:35:05 -0500 )edit

You can simply add ZZ: [ZZ(i) for i in x.str(skip_zeroes=True) if i.isdigit()].

B r u n o gravatar imageB r u n o ( 2016-08-18 08:41:43 -0500 )edit

Thank you!

logomath gravatar imagelogomath ( 2016-08-18 09:09:39 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-08-18 07:56:52 -0500

Seen: 73 times

Last updated: Aug 18 '16