def flatten(list_like, recursive=True):
    """ Flattens a list-like datastructure (returning a new list). """
    retval = []
    for element in list_like:
        if isinstance(element, list):
            if recursive:
                retval += flatten(element, recursive=True)
            else:
                retval += element
        else:
            retval.append(element)
    return retval