def frac_pi(a=lambda k: 0 if k == 0 else 2 * k - 1, b=lambda k: 4 if k == 1
     else (k - 1) ** 2, base=10):
    """Generate digits of a continued fraction a(0)+b(1)/(a(1)+b(2)/(...).

  Not just for generating digits of Pi, any `nicely` sequenced
  continued fraction can be generated using this function.

  Args:
    a: Represents a_k of a continued fraction.
    b: Represents b_k of a continued fraction.
    base: The base of the number system you wish as output,
      i.e., decimal, hex, etc.
  """
    (p0, q0), (p1, q1) = (a(0), 1), (a(1) * a(0) + b(1), a(1))
    k = 1
    while True:
        (d0, r0), (d1, r1) = divmod(p0, q0), divmod(p1, q1)
        if d0 == d1:
            yield d1
            p0, p1 = base * r0, base * r1
        else:
            k = k + 1
            x, y = a(k), b(k)
            (p0, q0), (p1, q1) = (p1, q1), (x * p1 + y * p0, x * q1 + y * q0)
