Created
September 26, 2016 23:08
-
-
Save Reflejo/bad89882699b11bb2208c6d9275c19ab 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
import bisect | |
from operator import itemgetter | |
units = [ | |
(1e-24, 'y'), | |
(1e-21, 'z'), | |
(1e-18, 'a'), | |
(1e-15, 'f'), | |
(1e-12, 'p'), | |
(1e-9, 'n'), | |
(1e-6, 'u'), | |
(1e-3, 'm'), | |
(1e-2, 'c'), | |
(1e-1, 'd'), | |
(1e3, 'k'), | |
(1e6, 'M'), | |
(1e9, 'G'), | |
(1e12, 'T'), | |
(1e15, 'P'), | |
(1e18, 'E'), | |
(1e21, 'Z'), | |
(1e24, 'Y'), | |
] | |
idx = bisect.bisect(map(itemgetter(0), units), 42e6) - 1 | |
magnitude, postfix = units[idx] | |
print 42e6 / magnitude, postfix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment