Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save ixxra/2d004e34b5e2d39e62b3 to your computer and use it in GitHub Desktop.
This is an example on howt to convert a list of digits into an integer
#Numbers from digits:
#How to convert a list of digits into a number
x = [2, 3, 4, 5, 9, 0]
#First way: ping-pong between string and integer
print int(''.join([str(d) for d in x]))
#Second way: plain arithmetic
powers = [10**k for k in range(len(x) - 1, -1, -1)]
print sum([d*p for d, p in zip(x, powers)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment