+ 6

How to split a number into digits?

How to split a number into digits and add them into the list? Eg, we have 123456 entered, and we need to get the ["1", "2", "3", "4", "5", "6"] list.

9th Sep 2018, 2:12 PM
Polina
Polina - avatar
4 Respostas
+ 8
I found a simpler option. Maybe it will be useful to someone. n = int(input()) #123456 lst = list(str(n))
9th Sep 2018, 2:38 PM
Polina
Polina - avatar
+ 6
You can do it like this too: n = list(input()) print(n)
9th Sep 2018, 2:46 PM
Paul
Paul - avatar
+ 3
Almost the same, but shorter: x = [] for i in input (): x.append(i) print(x)
9th Sep 2018, 2:34 PM
Paul
Paul - avatar
+ 2
num=str (input ()) lists=[] for i in range (len (num)): lists.append (num[i]) print (lists)
9th Sep 2018, 2:29 PM
Nafis Arinda Rizky Putra Handoko
Nafis Arinda Rizky Putra Handoko - avatar