How do I write the magic
function below?
>>> num = 123
>>> lst = magic(num)
>>>
>>> print lst, type(lst)
[1,
num = map(int, list(str(num)))
a = 123456
b = str(a)
c = []
for digit in b:
c.append (int(digit))
print c
You mean this?
num = 1234
lst = [int(i) for i in str(num)]
Just use :
a= str (num)
lst = list(a)
If it is named as magic, why not just use magic:
def magic(x):
if x < 10:
return [x]
else:
return magic(x//10) + [x%10]
magic = lambda num: map(int, str(num))
then just do
magic(12345)
or
magic(someInt) #or whatever