A simple task is how to find the first nonzero digit after a decimal point. I really need the distance between the decimal point and the first non-zero digit.
I know that I can do this in a few lines, but I would like to have some pythonic, beautiful and clean way to solve this problem.
While I have it
>>> 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)]
source share