def get_neighbour_squares(square, square_to_edges, edge_to_squares):
    """Get squares that are neighbours - have one matching edge."""
    neighbour_squares = []
    for square_edge in square_to_edges[square]:
        squares_with_edge = edge_to_squares[square_edge]
        if len(squares_with_edge) > 1:
            neighbour_squares.extend([
                one_square for one_square in squares_with_edge
                if one_square != square
            ])
    return neighbour_squares