Bicorn

decimal zeroes

Aug 3rd, 2021
536
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from itertools import takewhile
  2.  
  3. def decimal_zeroes(f):
  4.     # returns number of zeroes between decimal point and first non-zero digit
  5.     # returns 0 if there aren't any, or if it's an integer
  6.     try:
  7.         return sum(1 for _ in takewhile(lambda c: c == '0', str(f).split('.')[1]))
  8.     except IndexError:
  9.         return 0
RAW Paste Data