\
   Encodes an integer :attr:`n` in base ``len(alphabet)`` with 
   digits in :attr:`alphabet`.
 
   ::

      # 'ba'
      bx_encode(3, 'abc')

   :param n:            a positive integer.
   :param alphabet:     a 0-based iterable.

def bx_encode(n, alphabet):
   """\
   Encodes an integer :attr:`n` in base ``len(alphabet)`` with 
   digits in :attr:`alphabet`.
 
   ::

      # 'ba'
      bx_encode(3, 'abc')

   :param n:            a positive integer.
   :param alphabet:     a 0-based iterable.
   """
 
   if not isinstance(n, int):
      raise TypeError('an integer is required')

   base = len(alphabet)

   if n == 0:
      return alphabet[0]

   digits = []
   
   while n > 0:
      digits.append(alphabet[n % base])
      n = n // base
   
   digits.reverse()
   return ''.join(digits)