def single_element(x):
    """If x contains a single element, return it; otherwise return x"""
    try:
        if len(x) == 1:
            x = x[0]
    except TypeError:
        return x
    return x
