def unwrap_if_scalar(obj):
    """
    Unwraps obj if it is a sequence with a single item. Returns obj[0] if
    len(obj) == 1 and obj otherwise.
    """
    if len(obj) == 1:
        return obj[0]
    else:
        return obj