Created
September 1, 2014 15:23
-
-
Save ixxra/affada7a42a28ce04040 to your computer and use it in GitHub Desktop.
How to make a list of digits from a number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Aritmetic way to extract digits from a number | |
| #It should work in most programming languages | |
| x = 78449 | |
| digit = [] | |
| for k in range(4, -1, -1): | |
| digit.append( x / 10**k ) | |
| x = x % 10**k | |
| #After completing the loop, x no longer stores the | |
| #original value, but 0. Be warned! | |
| print digits | |
| #The python way: | |
| #It makes the hard easy and the imposible posible! | |
| x = 78449 | |
| digits = [int(c) for c in str(x)] | |
| print digitos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment