code: def _ensure_element(tup, elem):
      
      try:
          return tup, tup.index(elem)
      except ValueError:
          return tuple(chain(tup, (elem,))), len(tup)
docs: Create a tuple containing all elements of tup, plus elem.
  
      Returns the new tuple and the index of elem in the new tuple.