Created
September 1, 2014 15:37
-
-
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
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
| #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