Created
February 13, 2018 09:28
-
-
Save edwardgeorge/82f882fa2338b7b5dc9dd84389a0409d to your computer and use it in GitHub Desktop.
This file contains 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
from collections import namedtuple | |
from functools import reduce | |
Scientific = namedtuple("Scientific", "coefficient exponent") | |
def decimal_to_scientific(dec): | |
sign, digits, exp = dec.as_tuple() | |
coeff = reduce(lambda x, y: (x * 10) + y, digits, 0) | |
return Scientific(-coeff if sign else coeff, exp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment