def flatten(list_to_flatten):
    """Flatten the given nested structure"""
    if not isinstance(list_to_flatten, (list, tuple)):
        return list_to_flatten

    for elem in list_to_flatten:
        if isinstance(elem, (list, tuple)):
            for x in flatten(elem):
                yield x
        else:
            yield elem