3 ms·
If you want to be tricky about it, you can do it in one line in Python. Let d be your original integer. Then [(d%10**(n+1) - d%10**n) / 10**n for n in r
by pmiller2 6y ago
If you want to be tricky about it, you can do it in one line in Python. Let d be your original integer. Then
[(d%10**(n+1) - d%10**n) / 10**n for n in reversed(xrange(int(log10(d)+1)))]
will be a list containing the base 10 digits of d as integers.
Technically, you need to do
from math import log10
to make this work, but you can fit that on the same line with a little hacking around using __import__, such as this quick and very dirty attempt:
[ [(d%10**(n+1) - d%10**n) / 10**n for n in reversed(xrange(int(log10(d)+1)))] for log10 in [__import__("math", fromlist=["log10"]).log10]][0]
Edit:
Just to carry this a little further, if we interpret "a new integer that's the result of each of the original integer's digits squared" as doing something like this:
129 -> 1481
(i.e. 9 gets replaced with 81), then we can do it in one line like this:
int(''.join([str(x**2) for x in [(d%10**(n+1) - d%10**n) / 10**n for n in reversed(xrange(int(log10(d)+1)))]]))
- quacked 6y agoOoh, nice.