Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split an integer into an array of digits?

Tags:

python

My integer input is suppose 12345, I want to split and put it into an array as 1, 2, 3, 4, 5.
How will I be able to do it?

like image 221
Hick Avatar asked Dec 15 '09 11:12

Hick


People also ask

How do you separate integers into digits?

You can convert a number into String and then you can use toCharArray() or split() method to separate the number into digits.


1 Answers

>>> [int(i) for i in str(12345)]  [1, 2, 3, 4, 5] 
like image 195
luc Avatar answered Oct 02 '22 20:10

luc