x.digits() for x decimal
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.
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.
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']
Ok, how to reduce it to [3, 1, 4, 1, 6] ?
You can simply add ZZ
: [ZZ(i) for i in x.str(skip_zeroes=True) if i.isdigit()]
.
Thank you!
Asked: 8 years ago
Seen: 938 times
Last updated: Aug 18 '16