Is there a succinct way to split this negative integer into a list of digits? (Python)

370 views Asked by At

I can do this using an if statement but I feel like the code is too long for this simple operation.

num = -12345

-->inserts magical code<--

desired output

num_list = ['-1', '2', '3', '4', '5']

1

There are 1 answers

3
Juliano Costa On

You can simply use .split("\\B")

So the magical code would be:

String[] num_list = Integer.toString(num).split("\\B");