import itertools


def leading(predicate, iterable, start=0):
  """Returns the number of leading elements in the iterable for which
  the predicate is true.

  :param predicate:
      Predicate function of the form::

          f(x) -> bool
  :param iterable:
      Iterable sequence.
  :param start:
      Start index. (Number of items to skip before starting counting.)
  """
  i = 0
  for _ in itertools.takewhile(predicate,
                               itertools.islice(iterable, start, None, 1)):
    i += 1
  return i