简体   繁体   中英

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

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']

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

So the magical code would be:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM