def flatten(obj, ltypes=(list, tuple)):
    """Flatten a nested variable, by default only list/tuple combinations.

    Source: Mike C Fletcher's flatten http://www.bit.ly/2ULLMnm
    """
    ltype = type(obj)
    obj = list(obj)
    i = 0
    while i < len(obj):
        while isinstance(obj[i], ltypes) and not (
            isinstance(obj[i], str) and len(obj[i]) == 1
        ):
            if not obj[i]:
                obj.pop(i)
                i -= 1
                break
            else:
                obj[i : i + 1] = obj[i]
        i += 1
    return ltype(obj)