Reputation: 73
I was trying to code something in which It takes each number inside a number and put each number in array..
For example :
number (equals to) 21135
Array_number (equals to) [2,1,1,3,5]
Or get each number alone
number (equals to) 2261
N1 (equals to) 2
N2 (equals to) 2
N3 (equals to) 6
N4 (equals to) 1
I was thinking to convert it to a str
and find but it will be in unarranged order
Upvotes: 1
Views: 52
Reputation: 20137
simply use map(int, str())
>>>array_num = map(int, str(21135))
[2, 1, 1, 3, 5]
>>>int(''.join(map(str,array_num)))
21135 #will bring it back into normal
>>>
Upvotes: 1
Reputation: 83
Just a little hint without any code:
21135%10=5
21135-5:10%10=3
2113-3:10%10=1
211-1:10%10=1
21-1%10:10=2
Greetings
Upvotes: 1
Reputation: 565
Here you go :)
number = 21135
Array_number = [int(n) for n in str(number)]
Upvotes: 4