def flatten(list_to_flatten, remove_duplicates=False):
    """Returns a flattened copy of `list_to_flatten`. If `remove_duplicates`
    is set to `True`, duplicated item in `list_to_flatten` is removed.

    :param list_to_flatten: list to flatten out.
    :param remove_duplicates: set to `True` to remove duplicated items in
                              `list_to_flatten`. If set to `False` (default),
                              duplicates are preserved.
    """
    result = []
    for item in list_to_flatten:
        if hasattr(item, '__iter__') and not isinstance(item, str):
            result.extend(flatten(item))
        else:
            result.append(item)
    if remove_duplicates:
        return list(set(result))[::-1]
    else:
        return result