import six


def clean_layer_references(graph, layer_references):
    """
    Using list of layers and layer names convert it to
    complete list of layer objects. Function try to find
    layer by specified name in the graph and replate it in the
    layer list to the related object.

    Parameters
    ----------
    graph : LayerGraph instance
        Graph that has information about all layers from
        the ``layer_references`` list.

    layer_references : list, tuple
        List of layer instancens and layer names.

    Returns
    -------
    list of layers
    """
    layers = []

    for layer_reference in layer_references:
        if isinstance(layer_reference, six.string_types):
            layer_reference = graph.find_layer_by_name(layer_reference)

        layers.append(layer_reference)

    return layers