Simple problem, how to find the first non-zero digit after decimal point. What I really need is the distance between the decimal point and the first non-zero digit.
I know I could do it with a few lines but I’d like to have some pythonic, nice and clean way to solve this.
So far I have this
>>> t = [(123.0, 2), (12.3, 1), (1.23, 0), (0.1234, 0), (0.01234, -1), (0.000010101, -4)]
>>> dist = lambda x: str(float(x)).find('.') - 1
>>> [(x[1], dist(x[0])) for x in t]
[(2, 2), (1, 1), (0, 0), (0, 0), (-1, 0), (-4, 0)]
The easiest way seems to be
I interpreted the second entry in each pair of the list
tas your desired result, so I choseint()to round the logarithm towards zero: