def recolour(shape, source_colours, target_colour):
    """ Recolours a shape from source_colours to target_colour.

    >>> recolour([(0, 0, 1), (0, 1, 1), (0, 2, 1), (0, 3, 5)], [1], 4)
    [(0, 0, 4), (0, 1, 4), (0, 2, 4), (0, 3, 5)]

    >>> recolour([(0, 0, 1), (0, 1, 1), (0, 2, 2), (0, 3, 5)], [1, 2], 4)
    [(0, 0, 4), (0, 1, 4), (0, 2, 4), (0, 3, 5)]
    """

    new_shape = []
    for cell in shape:
        y, x, colour = cell

        if colour in source_colours:
            colour = target_colour

        new_shape.append((y, x, colour))

    return new_shape