Skip to content

Instantly share code, notes, and snippets.

@ixxra
Created September 1, 2014 15:23
Show Gist options
  • Select an option

  • Save ixxra/affada7a42a28ce04040 to your computer and use it in GitHub Desktop.

Select an option

Save ixxra/affada7a42a28ce04040 to your computer and use it in GitHub Desktop.
How to make a list of digits from a number
#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