code: def only(iterable, default=None, too_long=None):
      
      it = iter(iterable)
      value = next(it, default)
  
      try:
          next(it)
      except StopIteration:
          pass
      else:
          raise too_long or ValueError('too many items in iterable (expected 1)')
  
      return value
docs: If *iterable* has only one item, return it.
      If it has zero items, return *default*.
      If it has more than one item, raise the exception given by *too_long*,
      which is ``ValueError`` by default.
  
      >>> only([], default='missing')
      'missing'
      >>> only([1])
      1
      >>> only([1, 2])  # doctest: +IGNORE_EXCEPTION_DETAIL
      Traceback (most recent call last):
      ...
      ValueError: too many items in iterable (expected 1)'
      >>> only([1, 2], too_long=TypeError)  # doctest: +IGNORE_EXCEPTION_DETAIL
      Traceback (most recent call last):
      ...
      TypeError
  
      Note that :func:`only` attempts to advance *iterable* twice to ensure there
      is only one item.  See :func:`spy` or :func:`peekable` to check
      iterable contents less destructively.