+ 2
Split at integer to a list of its digits
how can you split an integer in python say 15 to separate elements of a list like [1,5]
5 ответов
+ 3
[int(i) for i in str(num)] and [i for i in input()] are already enough:
str is an iterable so you don't need a list; and input comes automatically as str.
+ 6
def split_int(n):
lst = []
while n:
n, m = divmod(n, 10)
lst = [m] + lst
return lst
print(split_int(15))
print(list(map(int, str(15))))
+ 3
[int(i) for i in input()] or with a given integer
[int(i) for i in str(integer)] or
split(str(integer))
+ 2
#The quick and easy way
num = 15
digits = [int(i) for i in list(str(num))]
print(digits)
+ 2
#assume that you assign 15 to num variable
num = 15
num = str(num)
lst = []
for i in num:
lst.append(int(i))
#if you want to check it
print(lst)