def _ensure_element ( tup , elem ) : try : return tup , tup . index ( elem ) except ValueError : return tuple ( chain ( tup , ( elem , ) ) ) , len ( tup )
python create single element tuple
Create a tuple containing all elements of tup plus elem .
def _ensure_element(tup, elem):
    """
    Create a tuple containing all elements of tup, plus elem.

    Returns the new tuple and the index of elem in the new tuple.
    """
    try:
        return tup, tup.index(elem)
    except ValueError:
        return tuple(chain(tup, (elem,))), len(tup)