def the(iterable, context=None):
    """ Returns the first element of an iterable, but requires there to be
      exactly one.
  """
    icontext = 'expected exactly one value'
    if context is not None:
        icontext = icontext + ' for ' + context
    is_first = True
    for elem in iterable:
        if is_first:
            it = elem
            is_first = False
        else:
            raise IndexError('%s: got more than one element (%s, %s, ...)' %
                (icontext, it, elem))
    if is_first:
        raise IndexError('%s: got no elements' % (icontext,))
    return it
